*default-pathname-defaults*
∗default-pathname-defaults∗ Variable
Value Type:
a pathname object.
Initial Value:
An implementation-dependent pathname, typically in the working directory that was current when Common Lisp was started up.
Description:
a pathname, used as the default whenever a function needs a default pathname and one is not supplied.
Examples:
;; This example illustrates a possible usage for a hypothetical Lisp running on a ;; DEC TOPS-20 file system. Since pathname conventions vary between Lisp
;; implementations and host file system types, it is not possible to provide a ;; general-purpose, conforming example.
\*default-pathname-defaults\* → #P"PS:<FRED>"
(merge-pathnames (make-pathname :name "CALENDAR"))
→ #P"PS:<FRED>CALENDAR"
(let ((\*default-pathname-defaults\* (pathname "<MARY>")))
(merge-pathnames (make-pathname :name "CALENDAR")))
→ #P"<MARY>CALENDAR"
Affected By:
The implementation.
Expanded Reference: *default-pathname-defaults*
Inspecting the default pathname
*default-pathname-defaults* holds a pathname used as the default whenever a function needs a default pathname and one is not explicitly supplied. Its initial value is implementation-dependent, typically the working directory.
(pathnamep *default-pathname-defaults*)
=> T
;; The value is implementation-dependent, e.g.:
*default-pathname-defaults*
;; => #P"/home/user/" ; typical on Unix
Functions that use the default
Many pathname functions such as merge-pathnames, parse-namestring, and enough-namestring use *default-pathname-defaults* when no explicit default is supplied.
;; merge-pathnames fills in from *default-pathname-defaults*
(let ((*default-pathname-defaults* #P"/home/user/projects/"))
(merge-pathnames "report.txt"))
;; => #P"/home/user/projects/report.txt"
Temporarily binding the default
You can use let to temporarily change the default pathname for a dynamic scope.
(let ((*default-pathname-defaults* #P"/tmp/"))
(namestring (merge-pathnames "output.log")))
=> "/tmp/output.log"
Effect on make-pathname
make-pathname also uses *default-pathname-defaults* to fill in the host component when no host is explicitly provided.
(let ((*default-pathname-defaults* #P"/var/data/"))
(namestring (merge-pathnames (make-pathname :name "info" :type "txt"))))
=> "/var/data/info.txt"