FunctionPackage: exclToCDocOverviewCGDocRelNotesFAQIndexPermutedIndex
Allegro CL version 8.1
Unrevised from 8.0 to 8.1.
8.0 version

chdir

Arguments: &optional directory

The new :osi module, released after the release of Allegro CL 6.2, has additional functionality relating to file handling. The symbol excl:chdir is exported from the new excl.osi package (as well as from the excl package). See OSI file handling functionality in os-interface.htm.

This function is designed to mimic the UNIX/DOS cd utility. In short, it extracts the directory component of directory and changes the current working directory to that. If the directory component is relative, the new directory is determined relative to the current working directory (as returned by current-directory). directory can be a pathname object or a string.

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 *default-pathname-defaults*:

(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:

pathname is

Action by chdir

not specified Change to the current user's home directory on UNIX, to c:\ on Windows.
A pathname object 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 typically /usr/local/acl62/ though your value may be different.

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).
"/usr/local/acl62/"
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 (chdir "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, (make-pathname :directory "tmp") creates the absolute pathname object with namestring "/tmp/" while (make-pathname :directory "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-2009, Franz Inc. Oakland, CA., USA. All rights reserved.
Documentation for Allegro CL version 8.1. This page was not revised from the 8.0 page.
Created 2009.7.29.

ToCDocOverviewCGDocRelNotesFAQIndexPermutedIndex
Allegro CL version 8.1
Unrevised from 8.0 to 8.1.
8.0 version