From: ···········@gmail.com
Subject: During (load), get the directory in which the .lisp file resides
Date: 
Message-ID: <1171740289.367993.128660@l53g2000cwa.googlegroups.com>
Hi,

As per title.

E.g., Someone calls my file like this:

            (load "/home/ublang/projects/gofer.lisp")

Then, within gofer.lisp, how do I determine the directory it is stored
in (not the OS notion of 'current directory')?


Thanks

Joubert

From: Pascal Bourguignon
Subject: Re: During (load), get the directory in which the .lisp file resides
Date: 
Message-ID: <87odnsa7z4.fsf@thalassa.informatimago.com>
···········@gmail.com writes:
> E.g., Someone calls my file like this:
>
>             (load "/home/ublang/projects/gofer.lisp")
>
> Then, within gofer.lisp, how do I determine the directory it is stored
> in (not the OS notion of 'current directory')?

    (pathname-directory *load-pathname*)

Or perhaps preferably:

    (make-pathname :name nil :type nil :version nil
                   :defaults *load-pathname*)

if what you want is a pathname...

Of course, depending on what you want to do with the directory
pathname, you could as well just keep *load-pathname* and make or
merge pathnames with it.


-- 
__Pascal Bourguignon__                     http://www.informatimago.com/

READ THIS BEFORE OPENING PACKAGE: According to certain suggested
versions of the Grand Unified Theory, the primary particles
constituting this product may decay to nothingness within the next
four hundred million years.
From: ···········@gmail.com
Subject: Re: During (load), get the directory in which the .lisp file resides
Date: 
Message-ID: <1171742512.517263.219740@l53g2000cwa.googlegroups.com>
On Feb 17, 2:40 pm, Pascal Bourguignon <····@informatimago.com> wrote:
> ···········@gmail.com writes:
> > E.g., Someone calls my file like this:
>
> >             (load "/home/ublang/projects/gofer.lisp")
>
> > Then, within gofer.lisp, how do I determine the directory it is stored
> > in (not the OS notion of 'current directory')?
>
>     (pathname-directory *load-pathname*)
>
> Or perhaps preferably:
>
>     (make-pathname :name nil :type nil :version nil
>                    :defaults *load-pathname*)
>
> if what you want is a pathname...
>
> Of course, depending on what you want to do with the directory
> pathname, you could as well just keep *load-pathname* and make or
> merge pathnames with it.
>
> --
> __Pascal Bourguignon__                    http://www.informatimago.com/
>
> READ THIS BEFORE OPENING PACKAGE: According to certain suggested
> versions of the Grand Unified Theory, the primary particles
> constituting this product may decay to nothingness within the next
> four hundred million years.

Great; thanks for your input, Pascal.

I'm now doing this:

(load (make-pathname :name "config" :type "lisp"
		     :directory (pathname-directory *load-pathname*)))

and it works beautifully. When this file gets loaded it now correctly
resolves and loads "config.lisp".

Cheers
Joubert
From: Harald Hanche-Olsen
Subject: Re: During (load), get the directory in which the .lisp file resides
Date: 
Message-ID: <pcod548bfqa.fsf@shuttle.math.ntnu.no>
+ ···········@gmail.com:

| I'm now doing this:
|
| (load (make-pathname :name "config" :type "lisp"
| 		     :directory (pathname-directory *load-pathname*)))

Which can be shortened to

(load (make-pathname  :name "config" :type "lisp"
                      :defaults *load-pathname*))

-- 
* Harald Hanche-Olsen     <URL:http://www.math.ntnu.no/~hanche/>
- It is undesirable to believe a proposition
  when there is no ground whatsoever for supposing it is true.
  -- Bertrand Russell
From: Pascal Bourguignon
Subject: Re: During (load), get the directory in which the .lisp file resides
Date: 
Message-ID: <87k5yg9wdf.fsf@thalassa.informatimago.com>
Harald Hanche-Olsen <······@math.ntnu.no> writes:

> + ···········@gmail.com:
>
> | I'm now doing this:
> |
> | (load (make-pathname :name "config" :type "lisp"
> | 		     :directory (pathname-directory *load-pathname*)))
>
> Which can be shortened to
>
> (load (make-pathname  :name "config" :type "lisp"
>                       :defaults *load-pathname*))

Actually it's much better, in the case the *LOAD-PATHNAME* is not on
the same device or same host as  *DEFAULT-PATHNAME-DEFAULTS*.

I would also set the :VERSION to NIL, to avoid any problem when you're
loading a specific version of the file (the versions of the sources
and of the config.lisp file are not necessarily the same).


-- 
__Pascal Bourguignon__                     http://www.informatimago.com/

READ THIS BEFORE OPENING PACKAGE: According to certain suggested
versions of the Grand Unified Theory, the primary particles
constituting this product may decay to nothingness within the next
four hundred million years.
From: Harald Hanche-Olsen
Subject: Re: During (load), get the directory in which the .lisp file resides
Date: 
Message-ID: <pcoejondcsk.fsf@shuttle.math.ntnu.no>
+ Pascal Bourguignon <···@informatimago.com>:

| Harald Hanche-Olsen <······@math.ntnu.no> writes:
|
|> (load (make-pathname  :name "config" :type "lisp"
|>                       :defaults *load-pathname*))
|
| I would also set the :VERSION to NIL, to avoid any problem when
| you're loading a specific version of the file (the versions of the
| sources and of the config.lisp file are not necessarily the same).

Not necessary, I think.  Quoth CLHS on make-pathname:

  After the components supplied explicitly by host, device, directory,
  name, type, and version are filled in, the merging rules used by
  merge-pathnames are used to fill in any unsupplied components from
  the defaults supplied by defaults.

And the description of merge-pathnames:

  If pathname does specify a name, then the version is not affected by
  default-pathname. If this process leaves the version missing, the
  default-version is used.

And the optional argument default-version to merge-pathnames is :newest.

-- 
* Harald Hanche-Olsen     <URL:http://www.math.ntnu.no/~hanche/>
- It is undesirable to believe a proposition
  when there is no ground whatsoever for supposing it is true.
  -- Bertrand Russell
From: Pascal Bourguignon
Subject: Re: During (load), get the directory in which the .lisp file resides
Date: 
Message-ID: <87bqjractf.fsf@thalassa.informatimago.com>
Harald Hanche-Olsen <······@math.ntnu.no> writes:

> + Pascal Bourguignon <···@informatimago.com>:
>
> | Harald Hanche-Olsen <······@math.ntnu.no> writes:
> |
> |> (load (make-pathname  :name "config" :type "lisp"
> |>                       :defaults *load-pathname*))
> |
> | I would also set the :VERSION to NIL, to avoid any problem when
> | you're loading a specific version of the file (the versions of the
> | sources and of the config.lisp file are not necessarily the same).
>
> Not necessary, I think.  Quoth CLHS on make-pathname:
>
>   After the components supplied explicitly by host, device, directory,
>   name, type, and version are filled in, the merging rules used by
>   merge-pathnames are used to fill in any unsupplied components from
>   the defaults supplied by defaults.
>
> And the description of merge-pathnames:
>
>   If pathname does specify a name, then the version is not affected by
>   default-pathname. If this process leaves the version missing, the
>   default-version is used.
>
> And the optional argument default-version to merge-pathnames is :newest.

Cool!

C/USER[124]> (pathname-version (make-pathname :name "test" :type "file" :version 2))
2
C/USER[125]> (pathname-version 
              (make-pathname :name "other" :type "type"
                             :defaults (make-pathname :name "test" :type "file"
                                                      :version 2)))
:NEWEST


-- 
__Pascal Bourguignon__                     http://www.informatimago.com/
In deep sleep hear sound,
Cat vomit hairball somewhere.
Will find in morning.