From: Martin M. <ma...@ma...> - 2014-02-17 17:16:25
|
Often Christophe, Email does not quite communicate the intent! I did not mean anything by the phrase "of course" .. it was just my way of saying it. No disparagement intended... Another way that I can express this is that I expected that this identity would hold (let ((pn (make-pathname :name "test*" :type "dat"))) (equalp pn (pathname (namestring pn)))) => T on ABCL and ACL, NIL on SBCL Consequently we can see that SBCL is somehow not consistently managing the presence of the * in the name slot. In fact it is parsing the name into a directory as we can see if we do this: This is SBCL: * (let ((pn (make-pathname :name "test*" :type "dat"))) (describe pn) (describe (pathname (namestring pn)))) #P"test\\*.dat" [structure-object] Slots with :INSTANCE allocation: HOST = #<SB-IMPL::WIN32-HOST {22472481}> DEVICE = NIL DIRECTORY = NIL NAME = "test*" TYPE = "dat" VERSION = NIL #P"test/*.dat" [structure-object] Slots with :INSTANCE allocation: HOST = #<SB-IMPL::WIN32-HOST {22472481}> DEVICE = NIL DIRECTORY = (:RELATIVE "test") NAME = :WILD TYPE = "dat" VERSION = :NEWEST This for comparison is ACL: cl-user(54): (let ((pn (make-pathname :name "test*" :type "dat"))) (describe pn) (describe (pathname (namestring pn)))) #P"test*.dat" is a structure of type pathname. It has these slots: excl::host nil excl::device nil directory nil excl::name "test*" type "dat" excl::version :unspecific namestring "test*.dat" excl::hash nil excl::dir-namestring nil excl::plist nil #P"test*.dat" is a structure of type pathname. It has these slots: excl::host nil excl::device nil directory nil excl::name "test*" type "dat" excl::version :unspecific namestring "test*.dat" excl::hash nil excl::dir-namestring ".\\" excl::plist nil Best wishes, Martin M On 2/17/2014 8:19 AM, Christophe Rhodes wrote: > Martin Mallinson <ma...@ma...> writes: > >> Here is a little more about this issue. Run this little code example to >> see the difference: >> >> (progn >> (with-open-file (s "test00.dat" :direction :output :if-exists >> :supersede)) >> (equalp (directory "test*.dat") (directory (make-pathname :name >> "test*" :type "dat")))) >> >> You will see that it returns NIL on SBCL and returns T on other Common >> LISP implementations, it should of course return T. > Why do you say "it should of course"? > > The object created from (pathname "test*.dat") involve the parsing of a > namestring into a pathname; that parsing happens in an > implementation-defined way, and SBCL defines it to parse in a relatively > friendly way the asterisk into the equivalent of a shell glob. If you > request the PATHNAME-NAME of #p"test*.dat", you should get an > SB-IMPL::PATTERN object. > > By contrast, MAKE-PATHNAME in SBCL does no parsing at all; the pathname > object it constructs has a PATHNAME-NAME being equal to "test*". > > When the filesystem is interrogated about these files, the first one > (with a PATTERN) is wild, and so matching rules are applied to find all > those files matching the pattern. The second, with the string > PATHNAME-NAME, is not a wild pathname; it will match exactly the file > whose five-character name is "test*" (and whose extension is "dat"), and > no other files. > >> It is not that the * is in the name, it is in the name in both cases, it >> is that some backslashes seem to get in there as well in SBCL. > The backslash is an artifact of print-read consistency requirements: if > you print a pathname, reading it back in must produce the same. Since > #p"test*.dat" is namestring syntax for a pattern, there must be an > alternative syntax for the name with a literal asterisk; that > alternative syntax escapes it with a backslash, thus: "test\\*". (The > backslash is doubled because in string syntax, the backslash is the > escape character; the string "test\\*" has six character elements: #\t, > #\e, #\s, #\t, #\\, #\*. > > Best wishes, > > Christophe > |