Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Dumb question, hopefully simple answer

5 views
Skip to first unread message

Fred Haineux

unread,
Jul 17, 1997, 3:00:00 AM7/17/97
to

Looking at the CLtL2's descriptions of paths made my head explode.

I have a bunch of files I want to load. I have a file cleverly called
"start.lisp" which would like to load them.

I have a bit of code like this:

(load "first.lisp")
(load "datastructures.lisp")
(load "objects.lisp")
(load "graphics.lisp")
(go!)

but of course, the place that lisp looks to get the files is not correct.

How can I supply a path that means "in the same folder as this-a-here file"?

Thank you. Sheesh.

Phil Stubblefield

unread,
Jul 17, 1997, 3:00:00 AM7/17/97
to Fred Haineux

Look at the definition of *LOAD-PATHNAME* (CLtL p. 658). When
loading a file, this variable is bound to the name of the file
being loaded. So what you want to do is:

(load (merge-pathnames "first.lisp" *load-pathname*))
(load (merge-pathnames "datastructures.lisp" *load-pathname*))
(load (merge-pathnames "objects.lisp" *load-pathname*))
(load (merge-pathnames "graphics.lisp" *load-pathname*))
(go!)

Or similarly:

(flet ((load-local (pathname)
(load (merge-pathnames pathname *load-pathname*))))
(load-local "first.lisp")
(load-local "datastructures.lisp")
(load-local "objects.lisp")
(load-local "graphics.lisp"))
(go!)


Phil Stubblefield
Rockwell Palo Alto Laboratory 415/325-7165
http://www.rpal.rockwell.com/~phil ph...@rpal.rockwell.com

Pierpaolo Bernardi

unread,
Jul 18, 1997, 3:00:00 AM7/18/97
to

Fred Haineux (b...@wetware.com) wrote:

...


: but of course, the place that lisp looks to get the files is not correct.

: How can I supply a path that means "in the same folder as this-a-here file"?

: Thank you. Sheesh.

check *load-file-truename* and merge-pathnames.

Will Fitzgerald

unread,
Jul 18, 1997, 3:00:00 AM7/18/97
to

There are no dumb questions, only inconsistent file systems.

You'll probably want to look at your LISP vendor's manual for information
on how it treats files and directories. Some of the problems are:

- different file systems have different conventions for directory structures,
- different file systems have different conventions for file names,
- there's nothing special about "lisp" as a file type,

Therefore, it's not obvious how, in general, to turn "first.lisp" into the
right file to load.

Here's some code, though, which is mildly cross platform and CLtL2 (Common
Lisp, The Language, version 2) compliant, that will probably do what you
want.

(defun this-files-pathname ()
"Returns the directory pathname of the file currently being loaded."
(car
(list
#+(and :allegro :unix) excl:*source-pathname*
#+lucid lucid::*source-pathname*
#+MCL (parse-namestring ccl::*LOADING-FILE-SOURCE-FILE*)
#+CLISP common-lisp::*load-pathname*
#+(and :coral (not MCL)) (car ccl::*loading-files*)
#+genera (concatenate 'string
(host-namestring sys:fdefine-file-pathname)
":"
sys:fdefine-file-pathname
)
#+next *source-pathname*
#-(or lucid :coral genera next mcl clisp (and :allegro :unix))
(error "Add Code here to implement this-files-pathname."))))

(defun this-files-directory ()
"returns a list of the current files directory"
(let ((source-pn (this-files-pathname)))
(if (pathnamep source-pn)
(pathname-directory (translate-logical-pathname source-pn))
NIL)))

(defun source-file-type () "lisp")

(defun load-from-current-directory (filename)
(let ((file-pathname
(if (stringp filename)
(parse-namestring filename)
(apply 'make-pathname (cdr filename))))
(directory (this-files-directory)))
(load
(merge-pathnames
(make-pathname :name (pathname-name file-pathname)
:type (or (pathname-type file-pathname)
(source-file-type))
:directory directory)))))

Then, in your "start.lisp" file, you could replace (load "first.lisp"),
etc., with
(load-from-current-directory "first.lisp"). Although it's probably still
safer to use:

(load-from-current-directory '(:file "first" :type "lisp"))
(load-from-current-directory '(:file "datastructures" :type "lisp"))

etc.

In article <bc-170797...@17.127.18.234>, b...@wetware.com (Fred
Haineux) wrote:

> Looking at the CLtL2's descriptions of paths made my head explode.
>
> I have a bunch of files I want to load. I have a file cleverly called
> "start.lisp" which would like to load them.
>
> I have a bit of code like this:
>
> (load "first.lisp")
> (load "datastructures.lisp")
> (load "objects.lisp")
> (load "graphics.lisp")
> (go!)
>

> but of course, the place that lisp looks to get the files is not correct.
>
> How can I supply a path that means "in the same folder as this-a-here file"?
>
> Thank you. Sheesh.

--
Will Fitzgerald
Intell/Agent Systems

Erik Naggum

unread,
Jul 19, 1997, 3:00:00 AM7/19/97
to

* Will Fitzgerald

| Here's some code, though, which is mildly cross platform and CLtL2 (Common
| Lisp, The Language, version 2) compliant, that will probably do what you
| want.

you may want to look up *load-pathname* and *load-truename* in CLtL2 or
Common Lisp the Standard (e.g., the HyperSpec).

#\Erik
--
Microsoft Pencil 4.0 -- the only virtual pencil whose tip breaks.

0 new messages