Skip to content

Instantly share code, notes, and snippets.

@privet-kitty
Created December 8, 2018 08:58
Show Gist options
  • Select an option

  • Save privet-kitty/5cad7e1af4c5a036a5e97a9f9f86dd69 to your computer and use it in GitHub Desktop.

Select an option

Save privet-kitty/5cad7e1af4c5a036a5e97a9f9f86dd69 to your computer and use it in GitHub Desktop.
On the portability of wild-pathname

Portability of wild pathname

On most CL implementations, cl:parse-namestring (or #P"...") interprets a unix-like pathname including wildcard (e.g. "/foo/**/bar/qux*.lisp") in a common way. However, there are minor differences in behaviour and facility. Below is a table summarizing the points.

* as one directory

SBCL CCL CLISP ABCL ECL ACL LW
(pathname-match-p #P"/foo/bar/baz" #P"/foo/*/baz") T T T T T T T

** as zero or more directories

SBCL CCL CLISP ABCL ECL ACL LW
(pathname-match-p #P"/foo/bar/baz/qux" #P"/foo/**/qux") T T T T T T T
(pathname-match-p #P"/foo/qux" #P"/foo/**/qux") T T T T T T T
(pathname-match-p #P"/foo/bar/baz/qux" #P"**/qux") NIL NIL NIL NIL NIL NIL NIL

* as a file name or file type

SBCL CCL CLISP ABCL ECL ACL LW
(pathname-match-p #P"/foo/bar" #P"/foo/*") T T T T T T T
(pathname-match-p #P"/foo/bar.lisp" #P"/foo/*") T T T T NIL T T
(pathname-match-p #P"/foo/bar" #P"/foo/*.*") T T T T T T T
(pathname-name #P"/foo/bar/*") :WILD :WILD :WILD :WILD :WILD :WILD :WILD
(pathname-type #P"/foo/bar/*") NIL NIL NIL NIL NIL NIL NIL
(pathname-match-p #P"/foo/bar.lisp" #P"/foo/bar.*") T T T T T T T
(pathname-match-p #P"/foo/.lisp" #P"/foo/.*") T T T T T T T
(pathname-name #P"/foo/bar/.*") #<obj>* NIL ".*" ".*" ".*" ".*" ""
(pathname-type #P"/foo/bar/.*") NIL :WILD NIL NIL NIL NIL :WILD

* SBCL provides a class sb-impl::pattern for this purpose, which is here virtually equivalent to ".*".

* as a part of directory name

SBCL CCL CLISP ABCL ECL ACL LW
(pathname-match-p #P"/foo/bar" #P"/foo*/bar") T T T T T NIL T
(pathname-match-p #P"/footprint/bar" #P"/foo*/bar") T T T T T T T

* as a part of file name or file type

SBCL CCL CLISP ABCL ECL ACL LW
(pathname-match-p #P"/foo/bar.js" #P"/foo/bar*.js") T T T T T T T
(pathname-match-p #P"/foo/bar.test.js" #P"/foo/bar*.js") T T T T T T T
(pathname-match-p #P"/foo/bar.js" #P"/foo/bar.*js") T T T T T T T
(pathname-match-p #P"/foo/bar.mjs" #P"/foo/bar.*js") T T T T T T T
(pathname-match-p #P"/foo/bar.test.js" #P"/foo/bar.*js") NIL NIL NIL NIL NIL NIL NIL

wildcard ?

SBCL CCL CLISP ABCL ECL ACL LW
(pathname-match-p #P"/foo1/baz" #P"/foo?/baz") T NIL T NIL T T NIL
(pathname-match-p #P"/foo/baz" #P"/foo?/baz") NIL NIL NIL NIL T NIL NIL
(pathname-match-p #P"/foo100/baz" #P"/foo?/baz") NIL NIL NIL NIL NIL NIL NIL

The version of each implementation is as follows:

  • SBCL: sbcl-1.4.2-win-x64
  • Clozure CL: ccl-1.11-f96-win-x64
  • CLISP: clisp-2.49-win-x86
  • ABCL: abcl-1.5.0-fasl43-win-x64
  • ECL: ecl-16.1.2-2cb60658-win-x86
  • Allegro CL: acl-10.1-win-x86
  • LispWorks: lwpe-6.1.1-win-x86
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment