From: Fred Haineux
Subject: Dumb question, hopefully simple answer
Date: 
Message-ID: <bc-1707971351340001@17.127.18.234>
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.

From: Phil Stubblefield
Subject: Re: Dumb question, hopefully simple answer
Date: 
Message-ID: <33CEEFDC.17CE@rpal.rockwell.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.

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                ····@rpal.rockwell.com
From: Pierpaolo Bernardi
Subject: Re: Dumb question, hopefully simple answer
Date: 
Message-ID: <5qo54c$v2a$1@pania.unipi.it>
Fred Haineux (··@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.
From: Will Fitzgerald
Subject: Re: Dumb question, hopefully simple answer
Date: 
Message-ID: <w-fitzgerald-1807971022170001@p4-0.net-link.net>
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 <···················@17.127.18.234>, ··@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
From: Erik Naggum
Subject: Re: Dumb question, hopefully simple answer
Date: 
Message-ID: <3078285829646726@naggum.no>
* 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.