The function current-pathname
is useful for loading other files relative to a file.
current-pathname
computes a pathname from the current operation as follows:
When evaluating or compiling an Editor buffer
Uses the pathname of the buffer, if available, otherwise uses the current working directory.
Uses the current working directory.
The pathname computed above is then translated to a physical pathname, and the argument relative-pathname is merged with this physical pathname. The pathname-type
of the result pathname is set to type if supplied, the pathname-version
is set to :newest
, and pathname is returned.
A useful value for type is nil
, which can be used to allow load
to choose between lisp or fasl regardless of the type of the current pathname.
defsystem uses current-pathname
with its :default-host
argument.
Suppose you want the file foo
to load the file bar
.
While loading the source file foo.lisp
:
(current-pathname "bar")
=>
#P"C:/temp/bar.lisp"
While loading the binary file foo.ofasl
:
(current-pathname "bar")
=>
#P"C:/temp/bar.ofasl"
To load bar.lisp
or bar.ofasl
according to the value of *load-fasl-or-lisp-file*
, regardless of whether foo.lisp
or foo.ofasl
is being loaded, specify type nil
:
(load (current-pathname "bar" nil))
LispWorks User Guide and Reference Manual - 13 Feb 2015