Skip to main content

*compile-file-truename*

compile-file-truename∗ Variable

Value Type:

The value of *compile-file-pathname* must always be a pathname or nil. The value of *compile-file-truename* must always be a physical pathname or nil.

Initial Value:

nil.

Description:

During a call to compile-file, *compile-file-pathname* is bound to the pathname denoted by the first argument to compile-file, merged against the defaults; that is, it is bound to (pathname (merge-pathnames input-file)). During the same time interval, *compile-file-truename* is bound to the truename of the file being compiled.

At other times, the value of these variables is nil.

If a break loop is entered while compile-file 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:

compile-file

load-pathname,

Expanded Reference: *compile-file-truename*

Nil outside of compile-file

Outside of a call to compile-file, both *compile-file-pathname* and *compile-file-truename* are nil.

*compile-file-pathname*
=> NIL

*compile-file-truename*
=> NIL

Bound during compile-file

During compilation, *compile-file-pathname* is bound to the merged pathname of the input file, and *compile-file-truename* is bound to the truename of the file being compiled.

;; Create a file that records these values during compilation
(with-open-file (s "/tmp/cl-cft-test.lisp" :direction :output
:if-exists :supersede)
(write-string
"(defparameter *recorded-cfp* *compile-file-pathname*)
(defparameter *recorded-cft* *compile-file-truename*)"
s))

(compile-file "/tmp/cl-cft-test.lisp")
(load (compile-file-pathname "/tmp/cl-cft-test.lisp"))

(pathnamep *recorded-cfp*)
;; => T

(pathnamep *recorded-cft*)
;; => T

Useful for locating resources relative to source

These variables enable code to find files relative to the source being compiled.

;; Inside a file being compiled, you might write:
;; (defvar *my-data-dir*
;; (merge-pathnames "data/" *compile-file-truename*))