I've got different behavior on sbcl and clisp in the following
situation. I have a simple directory structure:
.
./systems/s-xml
./systems/cl-gd
./systems/cdg
Now, I want to get all files/directories under systems.
In sbcl, i do (directory "systems/*.*") and I get what I want.
In clisp, i do the same, and I get nil. I also tried to construct the
pathname using make-pathname/merge-pathname, but under the clisp the
result is the same - nil.
What result is right? And how to do the thing I want in a portable way?
> Now, I want to get all files/directories under systems.
> In sbcl, i do (directory "systems/*.*") and I get what I want.
> In clisp, i do the same, and I get nil. I also tried to construct the
> pathname using make-pathname/merge-pathname, but under the clisp the
> result is the same - nil.
>
> What result is right? And how to do the thing I want in a portable
> way?
Pathnames are deliberately underspecified in CLHS. CL-FAD offers some
layer of compatibility:
CL-USER> (documentation 'cl-fad:list-directory 'function)
"Returns a fresh list of pathnames corresponding to the truenames of
all files within the directory named by the non-wild pathname
designator DIRNAME. The pathnames of sub-directories are returned in
directory form - see PATHNAME-AS-DIRECTORY."
--
polscy Lispnicy, łączmy się -- #lisp-pl na freenode
> Hello!
>
> I've got different behavior on sbcl and clisp in the following
> situation. I have a simple directory structure:
> .
> ./systems/s-xml
> ./systems/cl-gd
> ./systems/cdg
>
> Now, I want to get all files/directories under systems.
> In sbcl, i do (directory "systems/*.*") and I get what I want.
But 'erroneously'. "systems/*.*" is a file pathname, so you should
get only files (from the point of view of Common Lisp; of course, from
the point of view if unix, directories are files, hence the behavior
of SBCL).
Try: (append (directory "systems/*/") (directory "systems/*.*/"))
if you want both directories with and without dots, or just:
(directory "systems/*/")
if your directories don't contain dots.
> In clisp, i do the same, and I get nil. I also tried to construct the
> pathname using make-pathname/merge-pathname, but under the clisp the
> result is the same - nil.
(make-pathname :directory '(:relative "SYSTEMS" :wild)
:name nil :type nil :version nil :case :common)
--> #P"systems/*/" ; in both clisp and sbcl...
> What result is right? And how to do the thing I want in a portable way?
To do pathname stuff in a portable way is really difficult. Even
perhaps impossible. AFAIK, the only thing you can do portably is to
use logical pathnames to access only a subset of the files in the
physical file system (and not the same subset depending on the
implementation!).
--
__Pascal Bourguignon__
Since no one else has mentioned it, allow me to suggest looking at
chapter 15 of Peter Seibel's excellent (and free, electronically) book
"Practical Common Lisp." The chapter -
http://www.gigamonkeys.com/book/practical-a-portable-pathname-library.html
- is devoted to adding a layer on top of Common Lisp implementations
to abstract away their differences in pathname handling.
;; Gary
Stanislaw already mentioned CL-FAD, which is actually based on the code
in that book, but is further improved.
Pascal
--
My website: http://p-cos.net
Common Lisp Document Repository: http://cdr.eurolisp.org
Closer to MOP & ContextL: http://common-lisp.net/project/closer/