Go to the first, previous, next, last section, table of contents.


Filenames

Overview of Filenames

There are many kinds of file systems, varying widely both in their superficial syntactic details, and in their underlying power and structure. The facilities provided by Common Lisp for referring to and manipulating files has been chosen to be compatible with many kinds of file systems, while at the same time minimizing the program-visible differences between kinds of file systems.

Since file systems vary in their conventions for naming files, there are two distinct ways to represent filenames: as namestrings and as pathnames.

Namestrings as Filenames

A namestring @IGindex{namestring} is a string that represents a filename.

In general, the syntax of namestrings involves the use of implementation-defined conventions, usually those customary for the file system in which the named file resides. The only exception is the syntax of a logical pathname namestring, which is defined in this specification; see section Syntax of Logical Pathname Namestrings.

A conforming program must never unconditionally use a literal namestring other than a logical pathname namestring because Common Lisp does not define any namestring syntax other than that for logical pathnames that would be guaranteed to be portable. However, a conforming program can, if it is careful, successfully manipulate user-supplied data which contains or refers to non-portable namestrings.

A namestring can be coerced to a pathname by the functions pathname or parse-namestring.

Pathnames as Filenames

Pathnames @IGindex{pathname} are structured objects that can represent, in an implementation-independent way, the filenames that are used natively by an underlying file system.

In addition, pathnames can also represent certain partially composed filenames for which an underlying file system might not have a specific namestring representation.

A pathname need not correspond to any file that actually exists, and more than one pathname can refer to the same file. For example, the pathname with a version of :newest might refer to the same file as a pathname with the same components except a certain number as the version. Indeed, a pathname with version :newest might refer to different files as time passes, because the meaning of such a pathname depends on the state of the file system.

Some file systems naturally use a structural model for their filenames, while others do not. Within the Common Lisp pathname model, all filenames are seen as having a particular structure, even if that structure is not reflected in the underlying file system. The nature of the mapping between structure imposed by pathnames and the structure, if any, that is used by the underlying file system is implementation-defined.

Every pathname has six components: a host, a device, a directory, a name, a type, and a version. By naming files with pathnames, Common Lisp programs can work in essentially the same way even in file systems that seem superficially quite different. For a detailed description of these components, see section Pathname Components.

The mapping of the pathname components into the concepts peculiar to each file system is implementation-defined. There exist conceivable pathnames for which there is no mapping to a syntactically valid filename in a particular implementation. An implementation may use various strategies in an attempt to find a mapping; for example, an implementation may quietly truncate filenames that exceed length limitations imposed by the underlying file system, or ignore certain pathname components for which the file system provides no support. If such a mapping cannot be found, an error of type file-error is signaled.

The time at which this mapping and associated error signaling occurs is implementation-dependent. Specifically, it may occur at the time the pathname is constructed, when coercing a pathname to a namestring, or when an attempt is made to open or otherwise access the file designated by the pathname.

Figure 19--1 lists some defined names that are applicable to pathnames.

*default-pathname-defaults* namestring pathname-name directory-namestring open pathname-type enough-namestring parse-namestring pathname-version file-namestring pathname pathnamep file-string-length pathname-device translate-pathname host-namestring pathname-directory truename make-pathname pathname-host user-homedir-pathname merge-pathnames pathname-match-p wild-pathname-p

Figure 19--1: Pathname Operations

Parsing Namestrings Into Pathnames

Parsing is the operation used to convert a namestring into a pathname.

Except in the case of parsing logical pathname namestrings,

this operation is implementation-dependent, because the format of namestrings is implementation-dependent.

A conforming implementation is free to accommodate other file system features in its pathname representation and provides a parser that can process such specifications in namestrings. Conforming programs must not depend on any such features, since those features will not be portable.

Pathnames

Pathname Components

A pathname has six components: a host, a device, a directory, a name, a type, and a version.

The Pathname Host Component

The name of the file system on which the file resides, or the name of a logical host.

The Pathname Device Component

Corresponds to the "device" or "file structure" concept in many host file systems: the name of a logical or physical device containing files.

The Pathname Directory Component

Corresponds to the "directory" concept in many host file systems: the name of a group of related files.

The Pathname Name Component

The "name" part of a group of files that can be thought of as conceptually related.

The Pathname Type Component

Corresponds to the "filetype" or "extension" concept in many host file systems. This says what kind of file this is. This component is always a string, nil, :wild, or :unspecific.

The Pathname Version Component

Corresponds to the "version number" concept in many host file systems.

The version is either a positive integer or a symbol from the following list: nil, :wild, :unspecific, or :newest (refers to the largest version number that already exists in the file system when reading a file, or to a version number greater than any already existing in the file system when writing a new file). Implementations can define other special version symbols.

Interpreting Pathname Component Values

Strings in Component Values

Special Characters in Pathname Components

Strings in pathname component values never contain special characters that represent separation between pathname fields, such as slash in Unix filenames. Whether separator characters are permitted as part of a string in a pathname component is implementation-defined; however, if the implementation does permit it, it must arrange to properly "quote" the character for the file system when constructing a namestring. For example,

 ;; In a TOPS-20 implementation, which uses {^}V to quote 
 (NAMESTRING (MAKE-PATHNAME :HOST "OZ" :NAME "<TEST>"))
=>  #P"OZ:PS:{^}V<TEST{^}V>"
NOT=> #P"OZ:PS:<TEST>"

Case in Pathname Components

Namestrings always use local file system case conventions, but Common Lisp functions that manipulate pathname components allow the caller to select either of two conventions for representing case in component values by supplying a value for the :case keyword argument. Figure 19--2 lists the functions relating to pathnames that permit a :case argument:

make-pathname pathname-directory pathname-name pathname-device pathname-host pathname-type

Figure 19--2: Pathname functions using a :CASE argument

Local Case in Pathname Components

For the functions in Figure~19--2, a value of :local @IKindex{local} for the :case argument (the default for these functions) indicates that the functions should receive and yield strings in component values as if they were already represented according to the host file system's convention for case.

If the file system supports both cases, strings given or received as pathname component values under this protocol are to be used exactly as written. If the file system only supports one case, the strings will be translated to that case.

Common Case in Pathname Components

For the functions in Figure~19--2, a value of :common @IKindex{common} for the :case argument that these functions should receive and yield strings in component values according to the following conventions:

*
All uppercase means to use a file system's customary case.
*
All lowercase means to use the opposite of the customary case.
*
Mixed case represents itself.

Note that these conventions have been chosen in such a way that translation from :local to :common and back to :local is information-preserving.

Special Pathname Component Values

NIL as a Component Value

As a pathname component value, nil represents that the component is "unfilled"; see section Merging Pathnames.

The value of any pathname component can be nil.

When constructing a pathname, nil in the host component might mean a default host rather than an actual nil in some implementations.

:WILD as a Component Value

If :wild @IKindex{wild} is the value of a pathname component, that component is considered to be a wildcard, which matches anything.

A conforming program must be prepared to encounter a value of :wild as the value of any pathname component, or as an element of a list that is the value of the directory component.

When constructing a pathname, a conforming program may use :wild as the value of any or all of the directory, name, type, or version component, but must not use :wild as the value of the host, or device component.

If :wild is used as the value of the directory component in the construction of a pathname, the effect is equivalent to specifying the list (:absolute :wild-inferiors), or the same as (:absolute :wild) in a file system that does not support :wild-inferiors. @IKindex{wild-inferiors}

:UNSPECIFIC as a Component Value

If :unspecific @IKindex{unspecific} is the value of a pathname component, the component is considered to be "absent" or to "have no meaning" in the filename being represented by the pathname.

Whether a value of :unspecific is permitted for any component on any given file system accessible to the implementation is implementation-defined. A conforming program must never unconditionally use a :unspecific as the value of a pathname component because such a value is not guaranteed to be permissible in all implementations. However, a conforming program can, if it is careful, successfully manipulate user-supplied data which contains or refers to non-portable pathname components. And certainly a conforming program should be prepared for the possibility that any components of a pathname could be :unspecific.

When reading_1 the value of any pathname component, conforming programs should be prepared for the value to be :unspecific.

When writing_1 the value of any pathname component, the consequences are undefined if :unspecific is given for a pathname in a file system for which it does not make sense.

Relation between component values NIL and :UNSPECIFIC

If a pathname is converted to a namestring, the symbols nil and :unspecific cause the field to be treated as if it were empty. That is, both nil and :unspecific cause the component not to appear in the namestring.

However, when merging a pathname with a set of defaults, only a nil value for a component will be replaced with the default for that component, while a value of :unspecific will be left alone as if the field were "filled"; see the function merge-pathnames and section Merging Pathnames.

Restrictions on Wildcard Pathnames

Wildcard pathnames can be used with directory but not with open, and return true from wild-pathname-p. When examining wildcard components of a wildcard pathname, conforming programs must be prepared to encounter any of the following additional values in any component or any element of a list that is the directory component:

*
The symbol :wild, which matches anything.
*
A string containing implementation-dependent special wildcard characters.
*
Any object, representing an implementation-dependent wildcard pattern.

Restrictions on Examining Pathname Components

The space of possible objects that a conforming program must be prepared to read_1 as the value of a pathname component is substantially larger than the space of possible objects that a conforming program is permitted to write_1 into such a component.

While the values discussed in the subsections of this section, in section Special Pathname Component Values, and in section Restrictions on Wildcard Pathnames apply to values that might be seen when reading the component values, substantially more restrictive rules apply to constructing pathnames; see section Restrictions on Constructing Pathnames.

When examining pathname components, conforming programs should be aware of the following restrictions.

Restrictions on Examining a Pathname Host Component

It is implementation-dependent what object is used to represent the host.

Restrictions on Examining a Pathname Device Component

The device might be a string, :wild, :unspecific, or nil.

Note that :wild might result from an attempt to read_1 the pathname component, even though portable programs are restricted from writing_1 such a component value; see section Restrictions on Wildcard Pathnames and section Restrictions on Constructing Pathnames.

Restrictions on Examining a Pathname Directory Component

The directory might be a string, :wild, :unspecific, or nil.

The directory can be a list of strings and symbols.

The car of the list is one of the symbols :absolute @IKindex{absolute} or :relative @IKindex{relative} , meaning:

:absolute
A list whose car is the symbol :absolute represents a directory path starting from the root directory. The list (:absolute) represents the root directory. The list (:absolute "foo" "bar" "baz") represents the directory called "/foo/bar/baz" in Unix (except possibly for case).
:relative
A list whose car is the symbol :relative represents a directory path starting from a default directory. The list (:relative) has the same meaning as nil and hence is not used. The list (:relative "foo" "bar") represents the directory named "bar" in the directory named "foo" in the default directory.

Each remaining element of the list is a string or a symbol.

Each string names a single level of directory structure. The strings should contain only the directory names themselves--no punctuation characters.

In place of a string, at any point in the list, symbols can occur to indicate special file notations. Figure 19--3 lists the symbols that have standard meanings. Implementations are permitted to add additional objects of any type that is disjoint from string if necessary to represent features of their file systems that cannot be represented with the standard strings and symbols.

Supplying any non-string, including any of the symbols listed below, to a file system for which it does not make sense signals an error of type file-error. For example, Unix does not support :wild-inferiors in most implementations.

@IKindex{wild}

@IKindex{wild-inferiors}

@IKindex{up}

@IKindex{back}

Symbol Meaning :wild Wildcard match of one level of directory structure :wild-inferiors Wildcard match of any number of directory levels :up Go upward in directory structure (semantic) :back Go upward in directory structure (syntactic)

Figure 19--3: Special Markers In Directory Component

The following notes apply to the previous figure:

Invalid Combinations
Using :absolute or :wild-inferiors immediately followed by :up or :back signals an error of type file-error.
Syntactic vs Semantic
"Syntactic" means that the action of :back depends only on the pathname and not on the contents of the file system. "Semantic" means that the action of :up depends on the contents of the file system; to resolve a pathname containing :up to a pathname whose directory component contains only :absolute and strings requires probing the file system. :up differs from :back only in file systems that support multiple names for directories, perhaps via symbolic links. For example, suppose that there is a directory (:absolute "X" "Y" "Z") linked to (:absolute "A" "B" "C") and there also exist directories (:absolute "A" "B" "Q") and (:absolute "X" "Y" "Q"). Then (:absolute "X" "Y" "Z" :up "Q") designates (:absolute "A" "B" "Q") while (:absolute "X" "Y" "Z" :back "Q") designates (:absolute "X" "Y" "Q")

Directory Components in Non-Hierarchical File Systems

In non-hierarchical file systems, the only valid list values for the directory component of a pathname are (:absolute string) and (:absolute :wild). :relative directories and the keywords :wild-inferiors, :up, and :back are not used in non-hierarchical file systems.

Restrictions on Examining a Pathname Name Component

The name might be a string, :wild, :unspecific, or nil.

Restrictions on Examining a Pathname Type Component

The type might be a string, :wild, :unspecific, or nil.

Restrictions on Examining a Pathname Version Component

The version can be any symbol or any integer.

The symbol :newest refers to the largest version number that already exists in the file system when reading, overwriting, appending, superseding, or directory listing an existing file. The symbol :newest refers to the smallest version number greater than any existing version number when creating a new file.

The symbols nil, :unspecific, and :wild have special meanings and restrictions; see section Special Pathname Component Values and section Restrictions on Constructing Pathnames.

Other symbols and integers have implementation-defined meaning.

Notes about the Pathname Version Component

It is suggested, but not required, that implementations do the following:

*
Use positive integers starting at 1 as version numbers.
*
Recognize the symbol :oldest to designate the smallest existing version number.
*
Use keywords for other special versions.

Restrictions on Constructing Pathnames

When constructing a pathname from components, conforming programs must follow these rules:

*
Any component can be nil. nil in the host might mean a default host rather than an actual nil in some implementations.
*
The host, device, directory, name, and type can be strings. There are implementation-dependent limits on the number and type of characters in these strings.
*
The directory can be a list of strings and symbols. There are implementation-dependent limits on the list's length and contents.
*
The version can be :newest.
*
Any component can be taken from the corresponding component of another pathname. When the two pathnames are for different file systems (in implementations that support multiple file systems), an appropriate translation occurs. If no meaningful translation is possible, an error is signaled. The definitions of "appropriate" and "meaningful" are implementation-dependent.
*
An implementation might support other values for some components, but a portable program cannot use those values. A conforming program can use implementation-dependent values but this can make it non-portable; for example, it might work only with Unix file systems.

Merging Pathnames

Merging takes a pathname with unfilled components and supplies values for those components from a source of defaults.

If a component's value is nil, that component is considered to be unfilled. If a component's value is any non-nil object, including :unspecific, that component is considered to be filled.

Except as explicitly specified otherwise, for functions that manipulate or inquire about files in the file system, the pathname argument to such a function is merged with *default-pathname-defaults* before accessing the file system (as if by merge-pathnames).

Examples of Merging Pathnames

Although the following examples are possible to execute only in implementations which permit :unspecific in the indicated position andwhich permit four-letter type components, they serve to illustrate the basic concept of pathname merging.

 (pathname-type 
   (merge-pathnames (make-pathname :type "LISP")
                    (make-pathname :type "TEXT")))
=>  "LISP"

 (pathname-type 
   (merge-pathnames (make-pathname :type nil)
                    (make-pathname :type "LISP")))
=>  "LISP"

 (pathname-type 
   (merge-pathnames (make-pathname :type :unspecific)
                    (make-pathname :type "LISP")))
=>  :UNSPECIFIC

Logical Pathnames

Syntax of Logical Pathname Namestrings

The syntax of a logical pathname namestring is as follows. (Note that unlike many notational descriptions in this document, this is a syntactic description of character sequences, not a structural description of objects.)

logical-pathname ::=[!host host-marker] [!relative-directory-marker] {!directory directory-marker}{* } [!name] [type-marker !type [version-marker !version]]

host ::=!word

directory ::=!word | !wildcard-word | !wild-inferiors-word

name ::=!word | !wildcard-word

type ::=!word | !wildcard-word

version ::=!pos-int | newest-word | wildcard-version

host-marker---a colon.

relative-directory-marker---a semicolon.

directory-marker---a semicolon.

type-marker---a dot.

version-marker---a dot.

wild-inferiors-word---The two character sequence "**" (two asterisks).

newest-word---The six character sequence "newest" or the six character sequence "NEWEST".

wildcard-version---an asterisk.

wildcard-word---one or more asterisks, uppercase letters, digits, and hyphens, including at least one asterisk, with no two asterisks adjacent.

word---one or more uppercase letters, digits, and hyphens.

pos-int---a positive integer.

Additional Information about Parsing Logical Pathname Namestrings

The Host part of a Logical Pathname Namestring

The host must have been defined as a logical pathname host; this can be done by using setf of logical-pathname-translations.

The logical pathname host name "SYS" is reserved for the implementation. The existence and meaning of SYS: logical pathnames is implementation-defined.

The Device part of a Logical Pathname Namestring

There is no syntax for a logical pathname device since the device component of a logical pathname is always :unspecific; see section Unspecific Components of a Logical Pathname.

The Directory part of a Logical Pathname Namestring

If a relative-directory-marker precedes the directories, the directory component parsed is as relative; otherwise, the directory component is parsed as absolute.

If a wild-inferiors-marker is specified, it parses into :wild-inferiors.

The Type part of a Logical Pathname Namestring

The type of a logical pathname for a source file is "LISP". This should be translated into whatever type is appropriate in a physical pathname.

The Version part of a Logical Pathname Namestring

Some file systems do not have versions. Logical pathname translation to such a file system ignores the version. This implies that a program cannot rely on being able to store more than one version of a file named by a logical pathname.

If a wildcard-version is specified, it parses into :wild.

Wildcard Words in a Logical Pathname Namestring

Each asterisk in a wildcard-word matches a sequence of zero or more characters. The wildcard-word "*" parses into :wild; other wildcard-words parse into strings.

Lowercase Letters in a Logical Pathname Namestring

When parsing words and wildcard-words, lowercase letters are translated to uppercase.

Other Syntax in a Logical Pathname Namestring

The consequences of using characters other than those specified here in a logical pathname namestring are unspecified.

The consequences of using any value not specified here as a logical pathname component are unspecified.

Logical Pathname Components

Unspecific Components of a Logical Pathname

The device component of a logical pathname is always :unspecific; no other component of a logical pathname can be :unspecific.

Null Strings as Components of a Logical Pathname

The null string, "", is not a valid value for any component of a logical pathname.

Filenames Dictionary

pathname [System Class]

Class Precedence List::

pathname, t

Description::

A pathname is a structured object which represents a filename.

There are two kinds of pathnames---physical pathnames and logical pathnames.

logical-pathname [System Class]

Class Precedence List::

logical-pathname, pathname, t

Description::

A pathname that uses a namestring syntax that is implementation-independent, and that has component values that are implementation-independent. Logical pathnames do not refer directly to filenames

See Also::

section File System Concepts, section Sharpsign P, section Printing Pathnames

pathname [Function]

pathname pathspec => pathname

Arguments and Values::

pathspec---a pathname designator.

pathname---a pathname.

Description::

Returns the pathname denoted by pathspec.

If the pathspec designator is a stream, the stream can be either open or closed; in both cases, the pathname returned corresponds to the filename used to open the file. pathname returns the same pathname for a file stream after it is closed as it did when it was open.

If the pathspec designator is a file stream created by opening a logical pathname, a logical pathname is returned.

Examples::

 ;; There is a great degree of variability permitted here.  The next
 ;; several examples are intended to illustrate just a few of the many
 ;; possibilities.  Whether the name is canonicalized to a particular
 ;; case (either upper or lower) depends on both the file system and the
 ;; implementation since two different implementations using the same
 ;; file system might differ on many issues.  How information is stored
 ;; internally (and possibly presented in #S notation) might vary,
 ;; possibly requiring `accessors' such as PATHNAME-NAME to perform case
 ;; conversion upon access.  The format of a namestring is dependent both
 ;; on the file system and the implementation since, for example, one
 ;; implementation might include the host name in a namestring, and
 ;; another might not.  #S notation would generally only be used in a
 ;; situation where no appropriate namestring could be constructed for use
 ;; with #P.
 (setq p1 (pathname "test"))
=>  #P"CHOCOLATE:TEST" ; with case canonicalization (e.g., VMS)
OR=> #P"VANILLA:test"   ; without case canonicalization (e.g., Unix)
OR=> #P"test"
OR=> #S(PATHNAME :HOST "STRAWBERRY" :NAME "TEST")
OR=> #S(PATHNAME :HOST "BELGIAN-CHOCOLATE" :NAME "test")
 (setq p2 (pathname "test"))
=>  #P"CHOCOLATE:TEST"
OR=> #P"VANILLA:test"
OR=> #P"test"
OR=> #S(PATHNAME :HOST "STRAWBERRY" :NAME "TEST")
OR=> #S(PATHNAME :HOST "BELGIAN-CHOCOLATE" :NAME "test")
 (pathnamep p1) =>  true
 (eq p1 (pathname p1)) =>  true
 (eq p1 p2)
=>  true
OR=> false
 (with-open-file (stream "test" :direction :output)
   (pathname stream))
=>  #P"ORANGE-CHOCOLATE:>Gus>test.lisp.newest"

See Also::

pathname, logical-pathname, section File System Concepts,

section Pathnames as Filenames

make-pathname [Function]

make-pathname {&key host device directory name type version defaults case}
=> pathname

Arguments and Values::

host---a valid physical pathname host. Complicated defaulting behavior; see below.

device---a valid pathname device. Complicated defaulting behavior; see below.

directory---a valid pathname directory. Complicated defaulting behavior; see below.

name---a valid pathname name. Complicated defaulting behavior; see below.

type---a valid pathname type. Complicated defaulting behavior; see below.

version---a valid pathname version. Complicated defaulting behavior; see below.

defaults---a pathname designator. The default is a pathname whose host component is the same as the host component of the value of *default-pathname-defaults*, and whose other components are all nil.

case---one of :common or :local. The default is :local.

pathname---a pathname.

Description::

Constructs and returns a pathname from the supplied keyword arguments.

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.

Whenever a pathname is constructed the components may be canonicalized if appropriate. For the explanation of the arguments that can be supplied for each component, see section Pathname Components.

If case is supplied, it is treated as described in section Case in Pathname Components.

The resulting pathname is a logical pathname if and only its host component is a logical host or a string that names a defined logical host.

If the directory is a string, it should be the name of a top level directory, and should not contain any punctuation characters; that is, specifying a string, str, is equivalent to specifying the list (:absolute str). Specifying the symbol :wild is equivalent to specifying the list (:absolute :wild-inferiors), or (:absolute :wild) in a file system that does not support :wild-inferiors.

Examples::

 ;; Implementation A -- an implementation with access to a single
 ;;  Unix file system.  This implementation happens to never display
 ;;  the `host' information in a namestring, since there is only one host. 
 (make-pathname :directory '(:absolute "public" "games")
                :name "chess" :type "db")
=>  #P"/public/games/chess.db" 

 ;; Implementation B -- an implementation with access to one or more
 ;;  VMS file systems.  This implementation displays `host' information
 ;;  in the namestring only when the host is not the local host.
 ;;  It uses a double colon to separate a host name from the host's local
 ;;  file name.
 (make-pathname :directory '(:absolute "PUBLIC" "GAMES")
                :name "CHESS" :type "DB")
=>  #P"SYS$DISK:[PUBLIC.GAMES]CHESS.DB" 
 (make-pathname :host "BOBBY"
                :directory '(:absolute "PUBLIC" "GAMES")
                :name "CHESS" :type "DB")
=>  #P"BOBBY::SYS$DISK:[PUBLIC.GAMES]CHESS.DB" 

 ;; Implementation C -- an implementation with simultaneous access to
 ;;  multiple file systems from the same Lisp image.  In this 
 ;;  implementation, there is a convention that any text preceding the
 ;;  first colon in a pathname namestring is a host name.
 (dolist (case '(:common :local))
   (dolist (host '("MY-LISPM" "MY-VAX" "MY-UNIX"))
     (print (make-pathname :host host :case case
                           :directory '(:absolute "PUBLIC" "GAMES")
                           :name "CHESS" :type "DB"))))
 |>  #P"MY-LISPM:>public>games>chess.db"
 |>  #P"MY-VAX:SYS$DISK:[PUBLIC.GAMES]CHESS.DB"
 |>  #P"MY-UNIX:/public/games/chess.db"
 |>  #P"MY-LISPM:>public>games>chess.db" 
 |>  #P"MY-VAX:SYS$DISK:[PUBLIC.GAMES]CHESS.DB" 
 |>  #P"MY-UNIX:/PUBLIC/GAMES/CHESS.DB" 
=>  NIL

Affected By::

The file system.

See Also::

section merge-pathnames [Function] , pathname, logical-pathname, section File System Concepts,

section Pathnames as Filenames

Notes::

Portable programs should not supply :unspecific for any component. See section :UNSPECIFIC as a Component Value.

pathnamep [Function]

pathnamep object => generalized-boolean

Arguments and Values::

object---an object.

generalized-boolean---a generalized boolean.

Description::

Returns true if object is of type pathname; otherwise, returns false.

Examples::

 (setq q "test")  =>  "test"
 (pathnamep q) =>  false
 (setq q (pathname "test"))
=>  #S(PATHNAME :HOST NIL :DEVICE NIL :DIRECTORY NIL :NAME "test" :TYPE NIL
       :VERSION NIL)
 (pathnamep q) =>  true 
 (setq q (logical-pathname "SYS:SITE;FOO.SYSTEM"))
=>  #P"SYS:SITE;FOO.SYSTEM"
 (pathnamep q) =>  true

Notes::

 (pathnamep object) == (typep object 'pathname)

pathname-host, pathname-device, pathname-directory,

pathname-name, pathname-type, pathname-version

[Function]

pathname-host pathname {&key case} => host

pathname-device pathname {&key case} => device

pathname-directory pathname {&key case} => directory

pathname-name pathname {&key case} => name

pathname-type pathname {&key case} => type

pathname-version pathname => version

Arguments and Values::

pathname---a pathname designator.

case---one of :local or :common. The default is :local.

host---a valid pathname host.

device---a valid pathname device.

directory---a valid pathname directory.

name---a valid pathname name.

type---a valid pathname type.

version---a valid pathname version.

Description::

These functions return the components of pathname.

If the pathname designator is a pathname, it represents the name used to open the file. This may be, but is not required to be, the actual name of the file.

If case is supplied, it is treated as described in section Case in Pathname Components.

Examples::

 (setq q (make-pathname :host "KATHY"
                        :directory "CHAPMAN" 
                        :name "LOGIN" :type "COM"))
=>  #P"KATHY::[CHAPMAN]LOGIN.COM"
 (pathname-host q) =>  "KATHY"
 (pathname-name q) =>  "LOGIN"
 (pathname-type q) =>  "COM"

 ;; Because namestrings are used, the results shown in the remaining
 ;; examples are not necessarily the only possible results.  Mappings
 ;; from namestring representation to pathname representation are 
 ;; dependent both on the file system involved and on the implementation
 ;; (since there may be several implementations which can manipulate the
 ;; the same file system, and those implementations are not constrained
 ;; to agree on all details). Consult the documentation for each
 ;; implementation for specific information on how namestrings are treated
 ;; that implementation.

 ;; VMS
 (pathname-directory (parse-namestring "[FOO.*.BAR]BAZ.LSP"))
=>  (:ABSOLUTE "FOO" "BAR")
 (pathname-directory (parse-namestring "[FOO.*.BAR]BAZ.LSP") :case :common)
=>  (:ABSOLUTE "FOO" "BAR")

 ;; Unix
 (pathname-directory "foo.l") =>  NIL
 (pathname-device "foo.l") =>  :UNSPECIFIC
 (pathname-name "foo.l") =>  "foo"
 (pathname-name "foo.l" :case :local) =>  "foo"
 (pathname-name "foo.l" :case :common) =>  "FOO"
 (pathname-type "foo.l") =>  "l"
 (pathname-type "foo.l" :case :local) =>  "l"
 (pathname-type "foo.l" :case :common) =>  "L"
 (pathname-type "foo") =>  :UNSPECIFIC
 (pathname-type "foo" :case :common) =>  :UNSPECIFIC
 (pathname-type "foo.") =>  ""
 (pathname-type "foo." :case :common) =>  ""
 (pathname-directory (parse-namestring "/foo/bar/baz.lisp") :case :local)
=>  (:ABSOLUTE "foo" "bar")
 (pathname-directory (parse-namestring "/foo/bar/baz.lisp") :case :local)
=>  (:ABSOLUTE "FOO" "BAR")
 (pathname-directory (parse-namestring "../baz.lisp"))
=>  (:RELATIVE :UP)
 (PATHNAME-DIRECTORY (PARSE-NAMESTRING "/foo/BAR/../Mum/baz"))
=>  (:ABSOLUTE "foo" "BAR" :UP "Mum")
 (PATHNAME-DIRECTORY (PARSE-NAMESTRING "/foo/BAR/../Mum/baz") :case :common)
=>  (:ABSOLUTE "FOO" "bar" :UP "Mum")
 (PATHNAME-DIRECTORY (PARSE-NAMESTRING "/foo/*/bar/baz.l"))
=>  (:ABSOLUTE "foo" :WILD "bar")
 (PATHNAME-DIRECTORY (PARSE-NAMESTRING "/foo/*/bar/baz.l") :case :common)
=>  (:ABSOLUTE "FOO" :WILD "BAR")

 ;; Symbolics LMFS
 (pathname-directory (parse-namestring ">foo>**>bar>baz.lisp"))
=>  (:ABSOLUTE "foo" :WILD-INFERIORS "bar")
 (pathname-directory (parse-namestring ">foo>*>bar>baz.lisp"))
=>  (:ABSOLUTE "foo" :WILD "bar")
 (pathname-directory (parse-namestring ">foo>*>bar>baz.lisp") :case :common)
=>  (:ABSOLUTE "FOO" :WILD "BAR")
 (pathname-device (parse-namestring ">foo>baz.lisp")) =>  :UNSPECIFIC

Affected By::

The implementation and the host file system.

Exceptional Situations::

Should signal an error of type type-error if its first argument is not a pathname.

See Also::

pathname, logical-pathname, section File System Concepts,

section Pathnames as Filenames

load-logical-pathname-translations [Function]

load-logical-pathname-translations host => just-loaded

Arguments and Values::

host---a string.

just-loaded---a generalized boolean.

Description::

Searches for and loads the definition of a logical host named host, if it is not already defined. The specific nature of the search is implementation-defined.

If the host is already defined, no attempt to find or load a definition is attempted, and false is returned. If the host is not already defined, but a definition is successfully found and loaded, true is returned. Otherwise, an error is signaled.

Examples::

 (translate-logical-pathname "hacks:weather;barometer.lisp.newest")
 |>  Error: The logical host HACKS is not defined.
 (load-logical-pathname-translations "HACKS")
 |>  ;; Loading SYS:SITE;HACKS.TRANSLATIONS
 |>  ;; Loading done.
=>  true
 (translate-logical-pathname "hacks:weather;barometer.lisp.newest")
=>  #P"HELIUM:[SHARED.HACKS.WEATHER]BAROMETER.LSP;0"
 (load-logical-pathname-translations "HACKS")
=>  false

Exceptional Situations::

If no definition is found, an error of type error is signaled.

See Also::

logical-pathname

Notes::

Logical pathname definitions will be created not just by implementors but also by programmers. As such, it is important that the search strategy be documented. For example, an implementation might define that the definition of a host is to be found in a file called "host.translations" in some specifically named directory.

logical-pathname-translations [Accessor]

logical-pathname-translations host => translations

(setf ( logical-pathname-translations host) new-translations)

Arguments and Values::

host--a logical host designator.

translations, new-translations---a list.

Description::

Returns the host's list of translations. Each translation is a list of at least two elements: from-wildcard and to-wildcard. Any additional elements are implementation-defined. From-wildcard is a logical pathname whose host is host. To-wildcard is a pathname.

[Reviewer Note by Laddaga: Can this be a logical pathname?]

(setf (logical-pathname-translations host) translations) sets a logical pathname host's list of translations. If host is a string that has not been previously used as a logical pathname host, a new logical pathname host is defined; otherwise an existing host's translations are replaced. logical pathname host names are compared with string-equal.

When setting the translations list, each from-wildcard can be a logical pathname whose host is host or a logical pathname namestring parseable by (parse-namestring string host), where host represents the appropriate object as defined by parse-namestring. Each to-wildcard can be anything coercible to a pathname by (pathname to-wildcard). If to-wildcard coerces to a logical pathname, translate-logical-pathname will perform repeated translation steps when it uses it.

host is either the host component of a logical pathname or a string that has been defined as a logical pathname host name by setf of logical-pathname-translations.

Examples::

[Reviewer Note by Laddaga: Shouldn't there be some *.*'s in the list of translations for PROG below?]

 ;;;A very simple example of setting up a logical pathname host.  No
 ;;;translations are necessary to get around file system restrictions, so
 ;;;all that is necessary is to specify the root of the physical directory
 ;;;tree that contains the logical file system.
 ;;;The namestring syntax on the right-hand side is implementation-dependent.
 (setf (logical-pathname-translations "foo")
       '(("**;*.*.*"              "MY-LISPM:>library>foo>**>")))

 ;;;Sample use of that logical pathname.  The return value
 ;;;is implementation-dependent.          
 (translate-logical-pathname "foo:bar;baz;mum.quux.3")
=>  #P"MY-LISPM:>library>foo>bar>baz>mum.quux.3"

 ;;;A more complex example, dividing the files among two file servers
 ;;;and several different directories.  This Unix doesn't support
 ;;;:WILD-INFERIORS in the directory, so each directory level must
 ;;;be translated individually.  No file name or type translations
 ;;;are required except for .MAIL to .MBX.
 ;;;The namestring syntax on the right-hand side is implementation-dependent.
 (setf (logical-pathname-translations "prog")
       '(("RELEASED;*.*.*"        "MY-UNIX:/sys/bin/my-prog/")
         ("RELEASED;*;*.*.*"      "MY-UNIX:/sys/bin/my-prog/*/")
         ("EXPERIMENTAL;*.*.*"    "MY-UNIX:/usr/Joe/development/prog/")
         ("EXPERIMENTAL;DOCUMENTATION;*.*.*"
                                  "MY-VAX:SYS$DISK:[JOE.DOC]")
         ("EXPERIMENTAL;*;*.*.*"  "MY-UNIX:/usr/Joe/development/prog/*/")
         ("MAIL;**;*.MAIL"        "MY-VAX:SYS$DISK:[JOE.MAIL.PROG...]*.MBX")))

 ;;;Sample use of that logical pathname.  The return value
 ;;;is implementation-dependent.          
 (translate-logical-pathname "prog:mail;save;ideas.mail.3")
=>  #P"MY-VAX:SYS$DISK:[JOE.MAIL.PROG.SAVE]IDEAS.MBX.3"

 ;;;Example translations for a program that uses three files main.lisp,
 ;;;auxiliary.lisp, and documentation.lisp.  These translations might be
 ;;;supplied by a software supplier as examples.

 ;;;For Unix with long file names
 (setf (logical-pathname-translations "prog")
       '(("CODE;*.*.*"             "/lib/prog/")))

 ;;;Sample use of that logical pathname.  The return value
 ;;;is implementation-dependent.          
 (translate-logical-pathname "prog:code;documentation.lisp")
=>  #P"/lib/prog/documentation.lisp"

 ;;;For Unix with 14-character file names, using .lisp as the type
 (setf (logical-pathname-translations "prog")
       '(("CODE;DOCUMENTATION.*.*" "/lib/prog/docum.*")
         ("CODE;*.*.*"             "/lib/prog/")))

 ;;;Sample use of that logical pathname.  The return value
 ;;;is implementation-dependent.          
 (translate-logical-pathname "prog:code;documentation.lisp")
=>  #P"/lib/prog/docum.lisp"

 ;;;For Unix with 14-character file names, using .l as the type
 ;;;The second translation shortens the compiled file type to .b
 (setf (logical-pathname-translations "prog")
       `(("**;*.LISP.*"            ,(logical-pathname "PROG:**;*.L.*"))
         (,(compile-file-pathname (logical-pathname "PROG:**;*.LISP.*"))
                                   ,(logical-pathname "PROG:**;*.B.*"))
         ("CODE;DOCUMENTATION.*.*" "/lib/prog/documentatio.*")
         ("CODE;*.*.*"             "/lib/prog/")))

 ;;;Sample use of that logical pathname.  The return value
 ;;;is implementation-dependent.          
 (translate-logical-pathname "prog:code;documentation.lisp")
=>  #P"/lib/prog/documentatio.l"

 ;;;For a Cray with 6 character names and no directories, types, or versions.
 (setf (logical-pathname-translations "prog")
       (let ((l '(("MAIN" "PGMN")
                  ("AUXILIARY" "PGAUX")
                  ("DOCUMENTATION" "PGDOC")))
             (logpath (logical-pathname "prog:code;"))
             (phypath (pathname "XXX")))
         (append
           ;; Translations for source files
           (mapcar #'(lambda (x)
                       (let ((log (first x))
                             (phy (second x)))
                         (list (make-pathname :name log
                                              :type "LISP"
                                              :version :wild
                                              :defaults logpath)
                               (make-pathname :name phy
                                              :defaults phypath))))
                   l)
           ;; Translations for compiled files
           (mapcar #'(lambda (x)
                       (let* ((log (first x))
                              (phy (second x))
                              (com (compile-file-pathname
                                     (make-pathname :name log
                                                    :type "LISP"
                                                    :version :wild
                                                    :defaults logpath))))
                         (setq phy (concatenate 'string phy "B"))
                         (list com
                               (make-pathname :name phy
                                              :defaults phypath))))
                   l))))

 ;;;Sample use of that logical pathname.  The return value
 ;;;is implementation-dependent.          
 (translate-logical-pathname "prog:code;documentation.lisp")
=>  #P"PGDOC"

Exceptional Situations::

If host is incorrectly supplied, an error of type type-error is signaled.

See Also::

logical-pathname,

section Pathnames as Filenames

Notes::

Implementations can define additional functions that operate on logical pathname hosts, for example to specify additional translation rules or options.

logical-pathname [Function]

logical-pathname pathspec => logical-pathname

Arguments and Values::

pathspec---a logical pathname, a logical pathname namestring, or a stream.

logical-pathname---a logical pathname.

Description::

logical-pathname converts pathspec to a logical pathname and returns the new logical pathname. If pathspec is a logical pathname namestring, it should contain a host component and its following colon. If pathspec is a stream, it should be one for which pathname returns a logical pathname.

If pathspec is a stream, the stream can be either open or closed. logical-pathname returns the same logical pathname after a file is closed as it did when the file was open.

It is an error if pathspec is a stream that is created with make-two-way-stream, make-echo-stream, make-broadcast-stream, make-concatenated-stream, make-string-input-stream, or make-string-output-stream.

Exceptional Situations::

Signals an error of type type-error if pathspec isn't supplied correctly.

See Also::

logical-pathname, section translate-logical-pathname [Function] , section Logical Pathnames

*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.

namestring, file-namestring, directory-namestring,

host-namestring, enough-namestring

[Function]

namestring pathname => namestring

file-namestring pathname => namestring

directory-namestring pathname => namestring

host-namestring pathname => namestring

enough-namestring pathname {&optional defaults} => namestring

Arguments and Values::

pathname---a pathname designator.

defaults---a pathname designator.

The default is the value of *default-pathname-defaults*.

namestring---a string or nil.

[Editorial Note by KMP: Under what circumstances can NIL be returned??]

Description::

These functions convert pathname into a namestring. The name represented by pathname is returned as a namestring in an implementation-dependent canonical form.

namestring returns the full form of pathname.

file-namestring returns just the name, type, and version components of pathname.

directory-namestring returns the directory name portion.

host-namestring returns the host name.

enough-namestring returns an abbreviated namestring that is just sufficient to identify the file named by pathname when considered relative to the defaults. It is required that

 (merge-pathnames (enough-namestring pathname defaults) defaults)
== (merge-pathnames (parse-namestring pathname nil defaults) defaults)

in all cases, and the result of enough-namestring is the shortest reasonable string that will satisfy this criterion.

It is not necessarily possible to construct a valid > Whenever a pammon) => (:ABSOLUTE "FOO" "bar" :UP "Mum") (PATHNAME-DIRECTORY (PARSE-NAMESTRING "/foo/*/bar/baz.l")) => (:ABSOLUTE "foo" :WILD "bar") (PATHNAME-DIRECTORY (PARSE-NAMESTRING "/foo/*/bar/baz.l") :case :common) => (:ABSOLUTE "FOO" :WILD "BAR") ;; Symbolics LMFS (pathname-directory (parse-namestring ">foo>**>bar>baz.lisp")) => (:ABSOLUTE "foo" :WILD-INFERIORS "bar") (pathname-directory (parse-namestring ">foo>*>bar>baz.lisp")) => (:ABSOLUTE "foo" :WILD "bar") (pathname-directory (parse-namestring ">foo>*>bar>baz.lisp") :case :common) => (:ABSOLUTE "FOO" :WILD "BAR") (pathname-device (parse-namestring ">foo>baz.lisp")) => :UNSPECIFIC

Affected By::

The implementation and the host file system.

Exceptional Situations::

Should signal an error of type type-error if its first argument is not a pathname.

See Also::

pathname, logical-pathname, section File System Concepts,

section Pathnames as Filenames

load-logical-pathname-translations [Function]

load-logical-pathname-translations host => just-loaded

Arguments and Values::

host---a string.

just-loaded---a generalized boolean.

Description::

Searches for and loads the definition of a logical host named host, if it is not already defined. The specific nature of the search is implementation-defined.

If the host is already defined, no attempt to find or load a definition is attempted, and false is returned. If the host is not already defined, but a definition is successfully found and loaded, true is returned. Otherwise, an error is signaled.

Examples::

 (translate-logical-pathname "hacks:weather;barometer.lisp.newest")
 |>  Error: The logical host HACKS is not defined.
 (load-logical-pathname-translations "HACKS")
 |>  ;; Loading SYS:SITE;HACKS.TRANSLATIONS
 |>  ;; Loading done.
=>  true
 (translate-logical-pathname "hacks:weather;barometer.lisp.newest")
=>  #P"HELIUM:[SHARED.HACKS.WEATHER]BAROMETER.LSP;0"
 (load-logical-pathname-translations "HACKS")
=>  false

Exceptional Situations::

If no definition is found, an error of type error is signaled.

See Also::

logical-pathname

Notes::

Logical pathname definitions will be created not just by implementors but also by programmers. As such, it is important that the search strategy be documented. For example, an implementation might define that the definition of a host is to be found in a file called "host.translations" in some specifically named directory.

logical-pathname-translations [Accessor]

logical-pathname-translations host => translations

(setf ( logical-pathname-translations host) new-translations)

Arguments and Values::

host--a logical host designator.

translations, new-translations---a list.

Description::

Returns the host's list of translations. Each translation is a list of at least two elements: from-wildcard and to-wildcard. Any additional elements are implementation-defined. From-wildcard is a logical pathname whose host is host. To-wildcard is a pathname.

[Reviewer Note by Laddaga: Can this be a logical pathname?]

(setf (logical-pathname-translations host) translations) sets a logical pathname host's list of translations. If host is a string that has not been previously used as a logical pathname host, a new logical pathname host is defined; otherwise an existing host's translations are replaced. logical pathname host names are compared with string-equal.

When setting the translations list, each from-wildcard can be a logical pathname whose host is host or a logical pathname namestring parseable by (parse-namestring string host), where host represents the appropriate object as defined by parse-namestring. Each to-wildcard can be anything coercible to a pathname by (pathname to-wildcard). If to-wildcard coerces to a logical pathname, translate-logical-pathname will perform repeated translation steps when it uses it.

host is either the host component of a logical pathname or a string that has been defined as a logical pathname host name by setf of logical-pathname-translations.

Examples::

[Reviewer Note by Laddaga: Shouldn't there be some *.*'s in the list of translations for PROG below?]

 ;;;A very simple example of setting up a logical pathname host.  No
 ;;;translations are necessary to get around file system restrictions, so
 ;;;all that is necessary is to specify the root of the physical directory
 ;;;tree that contains the logical file system.
 ;;;The namestring syntax on the right-hand side is implementation-dependent.
 (setf (logical-pathname-translations "foo")
       '(("**;*.*.*"              "MY-LISPM:>library>foo>**>")))

 ;;;Sample use of that logical pathname.  The return value
 ;;;is implementation-dependent.          
 (translate-logical-pathname "foo:bar;baz;mum.quux.3")
=>  #P"MY-LISPM:>library>foo>bar>baz>mum.quux.3"

 ;;;A more complex example, dividing the files among two file servers
 ;;;and several different directories.  This Unix doesn't support
 ;;;:WILD-INFERIORS in the directory, so each directory level must
 ;;;be translated individually.  No file name or type translations
 ;;;are required except for .MAIL to .MBX.
 ;;;The namestring syntax on the right-hand side is implementation-dependent.
 (setf (logical-pathname-translations "prog")
       '(("RELEASED;*.*.*"        "MY-UNIX:/sys/bin/my-prog/")
         ("RELEASED;*;*.*.*"      "MY-UNIX:/sys/bin/my-prog/*/")
         ("EXPERIMENTAL;*.*.*"    "MY-UNIX:/usr/Joe/development/prog/")
         ("EXPERIMENTAL;DOCUMENTATION;*.*.*"
                                  "MY-VAX:SYS$DISK:[JOE.DOC]")
         ("EXPERIMENTAL;*;*.*.*"  "MY-UNIX:/usr/Joe/development/prog/*/")
         ("MAIL;**;*.MAIL"        "MY-VAX:SYS$DISK:[JOE.MAIL.PROG...]*.MBX")))

 ;;;Sample use of that logical pathname.  The return value
 ;;;is implementation-dependent.          
 (translate-logical-pathname "prog:mail;save;ideas.mail.3")
=>  #P"MY-VAX:SYS$DISK:[JOE.MAIL.PROG.SAVE]IDEAS.MBX.3"

 ;;;Example translations for a program that uses three files main.lisp,
 ;;;auxiliary.lisp, and documentation.lisp.  These translations might be
 ;;;supplied by a software supplier as examples.

 ;;;For Unix with long file names
 (setf (logical-pathname-translations "prog")
       '(("CODE;*.*.*"             "/lib/prog/")))

 ;;;Sample use of that logical pathname.  The return value
 ;;;is implementation-dependent.          
 (translate-logical-pathname "prog:code;documentation.lisp")
=>  #P"/lib/prog/documentation.lisp"

 ;;;For Unix with 14-character file names, using .lisp as the type
 (setf (logical-pathname-translations "prog")
       '(("CODE;DOCUMENTATION.*.*" "/lib/prog/docum.*")
         ("CODE;*.*.*"             "/lib/prog/")))

 ;;;Sample use of that logical pathname.  The return value
 ;;;is implementation-dependent.          
 (translate-logical-pathname "prog:code;documentation.lisp")
=>  #P"/lib/prog/docum.lisp"

 ;;;For Unix with 14-character file names, using .l as the type
 ;;;The second translation shortens the compiled file type to .b
 (setf (logical-pathname-translations "prog")
       `(("**;*.LISP.*"            ,(logical-pathname "PROG:**;*.L.*"))
         (,(compile-file-pathname (logical-pathname "PROG:**;*.LISP.*"))
                                   ,(logical-pathname "PROG:**;*.B.*"))
         ("CODE;DOCUMENTATION.*.*" "/lib/prog/documentatio.*")
         ("CODE;*.*.*"             "/lib/prog/")))

 ;;;Sample use of that logical pathname.  The return value
 ;;;is implementation-dependent.          
 (translate-logical-pathname "prog:code;documentation.lisp")
=>  #P"/lib/prog/documentatio.l"

 ;;;For a Cray with 6 character names and no directories, types, or versions.
 (setf (logical-pathname-translations "prog")
       (let ((l '(("MAIN" "PGMN")
                  ("AUXILIARY" "PGAUX")
                  ("DOCUMENTATION" "PGDOC")))
             (logpath (logical-pathname "prog:code;"))
             (phypath (pathname "XXX")))
         (append
           ;; Translations for source files
           (mapcar #'(lambda (x)
                       (let ((log (first x))
                             (phy (second x)))
                         (list (make-pathname :name log
                                              :type "LISP"
                                              :version :wild
                                              :defaults logpath)
                               (make-pathname :name phy
                                              :defaults phypath))))
                   l)
           ;; Translations for compiled files
           (mapcar #'(lambda (x)
                       (let* ((log (first x))
                              (phy (second x))
                              (com (compile-file-pathname
                                     (make-pathname :name log
                                                    :type "LISP"
                                                    :version :wild
                                                    :defaults logpath))))
                         (setq phy (concatenate 'string phy "B"))
                         (list com
                               (make-pathname :name phy
                                              :defaults phypath))))
                   l))))

 ;;;Sample use of that logical pathname.  The return value
 ;;;is implementation-dependent.          
 (translate-logical-pathname "prog:code;documentation.lisp")
=>  #P"PGDOC"

Exceptional Situations::

If host is incorrectly supplied, an error of type type-error is signaled.

See Also::

logical-pathname,

section Pathnames as Filenames

Notes::

Implementations can define additional functions that operate on logical pathname hosts, for example to specify additional translation rules or options.

logical-pathname [Function]

logical-pathname pathspec => logical-pathname

Arguments and Values::

pathspec---a logical pathname, a logical pathname namestring, or a stream.

logical-pathname---a logical pathname.

Description::

logical-pathname converts pathspec to a logical pathname and returns the new logical pathname. If pathspec is a logical pathname namestring, it should contain a host component and its following colon. If pathspec is a stream, it should be one for which pathname returns a logical pathname.

If pathspec is a stream, the stream can be either open or closed. logical-pathname returns the same logical pathname after a file is closed as it did when the file was open.

It is an error if pathspec is a stream that is created with make-two-way-stream, make-echo-stream, make-broadcast-stream, make-concatenated-stream, make-string-input-stream, or make-string-output-stream.

Exceptional Situations::

Signals an error of type type-error if pathspec isn't supplied correctly.

See Also::

logical-pathname, section translate-logical-pathname [Function] , section Logical Pathnames

*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.

namestring, file-namestring, directory-namestring,

host-namestring, enough-namestring

[Function]

namestring pathname => namestring

file-namestring pathname => namestring

directory-namestring pathname => namestring

host-namestring pathname => namestring

enough-namestring pathname {&optional defaults} => namestring

Arguments and Values::

pathname---a pathname designator.

defaults---a pathname designator.

The default is the value of *default-pathname-defaults*.

namestring---a string or nil.

[Editorial Note by KMP: Under what circumstances can NIL be returned??]

Description::

These functions convert pathname into a namestring. The name represented by pathname is returned as a namestring in an implementation-dependent canonical form.

namestring returns the full form of pathname.

file-namestring returns just the name, type, and version components of pathname.

directory-namestring returns the directory name portion.

host-namestring returns the host name.

enough-namestring returns an abbreviated namestring that is just sufficient to identify the file named by pathname when considered relative to the defaults. It is required that

 (merge-pathnames (enough-namestring pathname defaults) defaults)
== (merge-pathnames (parse-namestring pathname nil defaults) defaults)

in all cases, and the result of enough-namestring is the shortest reasonable string that will satisfy this criterion.

It is not necessarily possible to construct a valid > Whenever a pammon) => (:ABSOLUTE "FOO" "bar" :UP "Mum") (PATHNAME-DIRECTORY (PARSE-NAMESTRING "/foo/*/bar/baz.l")) => (:ABSOLUTE "foo" :WILD "bar") (PATHNAME-DIRECTORY (PARSE-NAMESTRING "/foo/*/bar/baz.l") :case :common) => (:ABSOLUTE "FOO" :WILD "BAR") ;; Symbolics LMFS (pathname-directory (parse-namestring ">foo>**>bar>baz.lisp")) => (:ABSOLUTE "foo" :WILD-INFERIORS "bar") (pathname-directory (parse-namestring ">foo>*>bar>baz.lisp")) => (:ABSOLUTE "foo" :WILD "bar") (pathname-directory (parse-namestring ">foo>*>bar>baz.lisp") :case :common) => (:ABSOLUTE "FOO" :WILD "BAR") (pathname-device (parse-namestring ">foo>baz.lisp")) => :UNSPECIFIC

Affected By::

The implementation and the host file system.

Exceptional Situations::

Should signal an error of type type-error if its first argument is not a pathname.

See Also::

pathname, logical-pathname, section File System Concepts,

section Pathnames as Filenames

load-logical-pathname-translations [Function]

load-logical-pathname-translations host => just-loaded

Arguments and Values::

host---a string.

just-loaded---a generalized boolean.

Description::

Searches for and loads the definition of a logical host named host, if it is not already defined. The specific nature of the search is implementation-defined.

If the host is already defined, no attempt to find or load a definition is attempted, and false is returned. If the host is not already defined, but a definition is successfully found and loaded, true is returned. Otherwise, an error is signaled.

Examples::

 (translate-logical-pathname "hacks:weather;barometer.lisp.newest")
 |>  Error: The logical host HACKS is not defined.
 (load-logical-pathname-translations "HACKS")
 |>  ;; Loading SYS:SITE;HACKS.TRANSLATIONS
 |>  ;; Loading done.
=>  true
 (translate-logical-pathname "hacks:weather;barometer.lisp.newest")
=>  #P"HELIUM:[SHARED.HACKS.WEATHER]BAROMETER.LSP;0"
 (load-logical-pathname-translations "HACKS")
=>  false

Exceptional Situations::

If no definition is found, an error of type error is signaled.

See Also::

logical-pathname

Notes::

Logical pathname definitions will be created not just by implementors but also by programmers. As such, it is important that the search strategy be documented. For example, an implementation might define that the definition of a host is to be found in a file called "host.translations" in some specifically named directory.

logical-pathname-translations [Accessor]

logical-pathname-translations host => translations

(setf ( logical-pathname-translations host) new-translations)

Arguments and Values::

host--a logical host designator.

translations, new-translations---a list.

Description::

Returns the host's list of translations. Each translation is a list of at least two elements: from-wildcard and to-wildcard. Any additional elements are implementation-defined. From-wildcard is a logical pathname whose host is host. To-wildcard is a pathname.

[Reviewer Note by Laddaga: Can this be a logical pathname?]

(setf (logical-pathname-translations host) translations) sets a logical pathname host's list of translations. If host is a string that has not been previously used as a logical pathname host, a new logical pathname host is defined; otherwise an existing host's translations are replaced. logical pathname host names are compared with string-equal.

When setting the translations list, each from-wildcard can be a logical pathname whose host is host or a logical pathname namestring parseable by (parse-namestring string host), where host represents the appropriate object as defined by parse-namestring. Each to-wildcard can be anything coercible to a pathname by (pathname to-wildcard). If to-wildcard coerces to a logical pathname, translate-logical-pathname will perform repeated translation steps when it uses it.

host is either the host component of a logical pathname or a string that has been defined as a logical pathname host name by setf of logical-pathname-translations.

Examples::

[Reviewer Note by Laddaga: Shouldn't there be some *.*'s in the list of translations for PROG below?]

 ;;;A very simple example of setting up a logical pathname host.  No
 ;;;translations are necessary to get around file system restrictions, so
 ;;;all that is necessary is to specify the root of the physical directory
 ;;;tree that contains the logical file system.
 ;;;The namestring syntax on the right-hand side is implementation-dependent.
 (setf (logical-pathname-translations "foo")
       '(("**;*.*.*"              "MY-LISPM:>library>foo>**>")))

 ;;;Sample use of that logical pathname.  The return value
 ;;;is implementation-dependent.          
 (translate-logical-pathname "foo:bar;baz;mum.quux.3")
=>  #P"MY-LISPM:>library>foo>bar>baz>mum.quux.3"

 ;;;A more complex example, dividing the files among two file servers
 ;;;and several different directories.  This Unix doesn't support
 ;;;:WILD-INFERIORS in the directory, so each directory level must
 ;;;be translated individually.  No file name or type translations
 ;;;are required except for .MAIL to .MBX.
 ;;;The namestring syntax on the right-hand side is implementation-dependent.
 (setf (logical-pathname-translations "prog")
       '(("RELEASED;*.*.*"        "MY-UNIX:/sys/bin/my-prog/")
         ("RELEASED;*;*.*.*"      "MY-UNIX:/sys/bin/my-prog/*/")
         ("EXPERIMENTAL;*.*.*"    "MY-UNIX:/usr/Joe/development/prog/")
         ("EXPERIMENTAL;DOCUMENTATION;*.*.*"
                                  "MY-VAX:SYS$DISK:[JOE.DOC]")
         ("EXPERIMENTAL;*;*.*.*"  "MY-UNIX:/usr/Joe/development/prog/*/")
         ("MAIL;**;*.MAIL"        "MY-VAX:SYS$DISK:[JOE.MAIL.PROG...]*.MBX")))

 ;;;Sample use of that logical pathname.  The return value
 ;;;is implementation-dependent.          
 (translate-logical-pathname "prog:mail;save;ideas.mail.3")
=>  #P"MY-VAX:SYS$DISK:[JOE.MAIL.PROG.SAVE]IDEAS.MBX.3"

 ;;;Example translations for a program that uses three files main.lisp,
 ;;;auxiliary.lisp, and documentation.lisp.  These translations might be
 ;;;supplied by a software supplier as examples.

 ;;;For Unix with long file names
 (setf (logical-pathname-translations "prog")
       '(("CODE;*.*.*"             "/lib/prog/")))

 ;;;Sample use of that logical pathname.  The return value
 ;;;is implementation-dependent.          
 (translate-logical-pathname "prog:code;documentation.lisp")
=>  #P"/lib/prog/documentation.lisp"

 ;;;For Unix with 14-character file names, using .lisp as the type
 (setf (logical-pathname-translations "prog")
       '(("CODE;DOCUMENTATION.*.*" "/lib/prog/docum.*")
         ("CODE;*.*.*"             "/lib/prog/")))

 ;;;Sample use of that logical pathname.  The return value
 ;;;is implementation-dependent.          
 (translate-logical-pathname "prog:code;documentation.lisp")
=>  #P"/lib/prog/docum.lisp"

 ;;;For Unix with 14-character file names, using .l as the type
 ;;;The second translation shortens the compiled file type to .b
 (setf (logical-pathname-translations "prog")
       `(("**;*.LISP.*"            ,(logical-pathname "PROG:**;*.L.*"))
         (,(compile-file-pathname (logical-pathname "PROG:**;*.LISP.*"))
                                   ,(logical-pathname "PROG:**;*.B.*"))
         ("CODE;DOCUMENTATION.*.*" "/lib/prog/documentatio.*")
         ("CODE;*.*.*"             "/lib/prog/")))

 ;;;Sample use of that logical pathname.  The return value
 ;;;is implementation-dependent.          
 (translate-logical-pathname "prog:code;documentation.lisp")
=>  #P"/lib/prog/documentatio.l"

 ;;;For a Cray with 6 character names and no directories, types, or versions.
 (setf (logical-pathname-translations "prog")
       (let ((l '(("MAIN" "PGMN")
                  ("AUXILIARY" "PGAUX")
                  ("DOCUMENTATION" "PGDOC")))
             (logpath (logical-pathname "prog:code;"))
             (phypath (pathname "XXX")))
         (append
           ;; Translations for source files
           (mapcar #'(lambda (x)
                       (let ((log (first x))
                             (phy (second x)))
                         (list (make-pathname :name log
                                              :type "LISP"
                                              :version :wild
                                              :defaults logpath)
                               (make-pathname :name phy
                                              :defaults phypath))))
                   l)
           ;; Translations for compiled files
           (mapcar #'(lambda (x)
                       (let* ((log (first x))
                              (phy (second x))
                              (com (compile-file-pathname
                                     (make-pathname :name log
                                                    :type "LISP"
                                                    :version :wild
                                                    :defaults logpath))))
                         (setq phy (concatenate 'string phy "B"))
                         (list com
                               (make-pathname :name phy
                                              :defaults phypath))))
                   l))))

 ;;;Sample use of that logical pathname.  The return value
 ;;;is implementation-dependent.          
 (translate-logical-pathname "prog:code;documentation.lisp")
=>  #P"PGDOC"

Exceptional Situations::

If host is incorrectly supplied, an error of type type-error is signaled.

See Also::

logical-pathname,

section Pathnames as Filenames

Notes::

Implementations can define additional functions that operate on logical pathname hosts, for example to specify additional translation rules or options.

logical-pathname [Function]

logical-pathname pathspec => logical-pathname

Arguments and Values::

pathspec---a logical pathname, a logical pathname namestring, or a stream.

logical-pathname---a logical pathname.

Description::

logical-pathname converts pathspec to a logical pathname and returns the new logical pathname. If pathspec is a logical pathname namestring, it should contain a host component and its following colon. If pathspec is a stream, it should be one for which pathname returns a logical pathname.

If pathspec is a stream, the stream can be either open or closed. logical-pathname returns the same logical pathname after a file is closed as it did when the file was open.

It is an error if pathspec is a stream that is created with make-two-way-stream, make-echo-stream, make-broadcast-stream, make-concatenated-stream, make-string-input-stream, or make-string-output-stream.

Exceptional Situatio