Page 1 of 1

Different behavior of SBCL and CLISP on 'directory' function

Posted: Sat Nov 21, 2009 5:26 am
by kzn
Hello!

I have following directory structure:
.
./systems/s-xml
./systems/uffi
./systems/cdg

I want to get all entries under systems directory - a list of 3 items.
I call '(directory "systems/*.*")' from . to get the entries.

However, I get different results under sbcl and clisp:
under sbcl the function call works fine and return desired entries,
and under clisp the function call returns nil.
I tried to use make-pathname/merge-pathname, but they yield same results.

Which behavior is right? And if it is implementation dependent, what is the right way to do this?

Re: Different behavior of SBCL and CLISP on 'directory' function

Posted: Sun Nov 29, 2009 6:03 am
by Harleqin
I guess that your problem is the "*.*". While a special significance is often assigned to the last dot in a filename (the part after it being treated as an "extension"), for naming purposes this is irrelevant---EXCEPT in some operating systems like DOS (and Windows, which is based on it): here, the dot doesn't really "exist" but is just a notation for showing the two parts of a filename as a single string.

As a consequence, users of DOS and its descendants have a habit or need of writing "*.*", not just "*", when they mean "all files". On other systems, this would mean "all files that have a dot somewhere in their names". Since the directories you showed do not contain dots, this can be a problem of different expectations from the file system and the Lisp system resp. your application.

As an aside, the Common Lisp standard itself makes no assumptions about the underlying operating system; read about its filename handling in the CLHS.

So, the easiest way in your case might be to use "*" instead of "*.*". If you need different designators in different environments, you might have to use conditional reading using the "#+" or "#-" reader macros (see the CLHS).