*load-truename*
∗load-truename∗ Variable
Value Type:
The value of *load-pathname* must always be a pathname or nil. The value of *load-truename* must always be a physical pathname or nil.
Initial Value:
nil.
Description:
During a call to load, *load-pathname* is bound to the pathname denoted by the the first argument to load, merged against the defaults; that is, it is bound to (pathname (merge-pathnames filespec)). During the same time interval, *load-truename* is bound to the truename of the file being loaded.
At other times, the value of these variables is nil.
If a break loop is entered while load is ongoing, it is implementation-dependent whether these variables retain the values they had just prior to entering the break loop or whether they are bound to nil.
The consequences are unspecified if an attempt is made to assign or bind either of these variables.
Affected By:
The file system.
See Also:
load∗compile-print∗,
Expanded Reference: *load-truename*
Nil outside of load
Outside of a call to load, both *load-pathname* and *load-truename* are nil.
*load-pathname*
;; => NIL
*load-truename*
;; => NIL
Bound during load
During loading, *load-pathname* is bound to the merged pathname argument, and *load-truename* is bound to the truename of the file being loaded.
;; Create a file that captures these values during loading
(with-open-file (s "/tmp/cl-lt-test.lisp" :direction :output
:if-exists :supersede)
(write-string
"(defparameter *my-load-path* *load-pathname*)
(defparameter *my-load-true* *load-truename*)"
s))
(load "/tmp/cl-lt-test.lisp")
=> T
(pathnamep *my-load-path*)
=> T
(pathnamep *my-load-true*)
=> T
Locating resources relative to the loaded file
A common pattern is to find data files or configuration files relative to the file being loaded.
;; Inside a file being loaded:
;; (defvar *config-path*
;; (merge-pathnames "config.dat" *load-truename*))