|Allegro CL version 8.2|
Unrevised from 8.1 to 8.2.
Arguments: &optional directory
:osi module has additional functionality
relating to file handling. The symbol
exported from the new
excl.osi package (as well as
excl package). See OSI file handling functionality in
This function is designed to mimic the UNIX/DOS cd utility. directory, if supplied, must be a pathname or sting naming a directory (it cannot name a file). Assuming it exists, that directory will become the current working directory. If the directory is relative, the new directory is determined relative to the current working directory (as returned by current-directory). If directory is a string and does not contain a trailing / (so "/usr/tmp" rather than "/usr/tmp/" -- backslashes can be used when on Windows), it is filled in automatically.
If you happen to have the pathname of a file, applying either path-namestring or path-pathname to it will return a value suitable as an argument to chdir:
(setq path (pathname "/net/gemini/home/dm/xml-fns.cl")) (chdir path) -> ERROR (chdir (path-pathname path)) RETURNS "/net/gemini/home/dm/" (chdir (path-namestring path)) RETURNS "/net/gemini/home/dm/"
Note that this function does not modify the value of
*default-pathname-defaults*. Therefore, after
calling this function, it is likely that the current directory, as
returned by current-directory, will be differrent from the
directory specified in
*default-pathname-defaults*. The related
top-level command :cd does modify
the value of
*default-pathname-defaults*. The following form
modifies both the current directory and
(setf *default-pathname-defaults* (pathname (chdir directory)))
Because of a mismatch between UNIX and Common Lisp interpreting of strings naming directories, string arguments are handled specially, as we describe now. The following table shows the behavior of chdir given various values of pathname:
Action by chdir
|not specified||Change to the current user's home directory. (See What user-homedir-pathname does on Windows in implementation.htm for a discussion of what a home directory means on Windows.) for|
|A pathname object naming a directory||Extract the directory component of the pathname (translating first if it is a logical pathname). Change to that directory. Relative pathnames are resolved with respect to the current working directory (as returned by current-directory).|
|A string containing a /, : (colon), or ; (semicolon) naming a pathname||Convert to a pathname object, then continue as in the `A pathname object' row of this table.|
|A string without a /, : (colon), or ; (semicolon).||Add a / to the end of the string, convert to a pathname object, then continue as in the `A pathname object' row of this table. See Note 1 below.|
Examples. The current Unix user's home directory is /usr/tech/doe/. The directory /usr/tech/doe/tmp/ exists. The Allegro directory for the Lisp image is assumed to be /usr/local/acl/ though the actual value contains by default the release number and is in any case user-settable.
user(15): (chdir) ;; no argument: change to user home directory "/usr/tech/doe/" user(16): (chdir "sys:") ;; a string naming a logical pathname which translates ;; to the Allegro directory (the value you see may be different ;; usually containing the release number). "/usr/local/acl/" user(17): (chdir) "/usr/tech/doe/" user(18): (chdir "tmp") ;; change to the tmp/ subdirectory "tmp/" user(19): (chdir (make-pathname :directory "tmp")) ;; The absolute directory "/tmp/" user(20): (chdir) "/usr/tech/doe/" user(21):
Note 1. A / is added to the end of a string that
does contain a /, ;, or : in order that
"tmp") will work as `cd tmp' does in UNIX and DOS:
change to the tmp subdirectory of the current
directory. Following the ANSI CL spec,
"tmp") creates the absolute pathname object with
namestring "/tmp/" while
"tmp/") creates the relative pathname with namestring
"tmp/". It is the second that follows the UNIX
paradigm. Appending a / guarantees that effect.
chdir returns the namestring of the directory component of the pathname changed to. Note that this may not be the new current directory (as returned by current-directory).
Warning about interaction between chdir and foreign loading and dumplisp: if the command line used to start Lisp identified the Allegro CL image with a relative pathname (`./mlisp', for example), you cannot do the first load of foreign code or dump an image with dumplisp after changing the directory with this function. Therefore, if you started Lisp with a relative pathname, do at least one foreign load before calling chdir and do not call dumplisp after calling chdir. (The problem is that when doing the first foreign load or a dumplisp, Lisp needs to examine the running image, which it finds by examining the command line that invoked the image. If Lisp is identified on the command line with a relative pathname and the current directory has been changed, the relative pathname merged with the current directory no longer points to the running image. Changing back to the original current directory fixes the problem.)
See :cd, :popd, and :pushd, which also change the current directory. See also os-interface.htm for general information on the interface between Allegro CL and the operating system.
Copyright (c) 1998-2015, Franz Inc. Oakland, CA., USA. All rights reserved.
Documentation for Allegro CL version 8.2. This page was not revised from the 8.1 page.
|Allegro CL version 8.2|
Unrevised from 8.1 to 8.2.