Common Lisp the Language, 2nd Edition
Next: An Example
Up: Packages
Previous: Package System
Functions
A module is a Common Lisp subsystem that is loaded from one or more files. A module is normally loaded as a single unit, regardless of how many files are involved. A module may consist of one package or several packages. The file-loading process is necessarily implementation-dependent, but Common Lisp provides some very simple portable machinery for naming modules, for keeping track of which modules have been loaded, and for loading modules as a unit.
X3J13 voted in January 1989 (REQUIRE-PATHNAME-DEFAULTS) to eliminate
the entire module facility from the language; that is, the variable
*modules*
and the functions provide
and
require
are deleted. X3J13 commented that the file-loading
feature of require
is not portable, and that the remaining
functionality is easily implemented by user code. (I will add that in
any case the specification of require
is so vague that
different implementations are likely to have differing behavior.)
[Variable]
*modules*
The variable *modules*
is a list of names of the modules
that have been loaded into the Lisp system so far. This list is used by
the functions provide
and require
.
[Function]
provide
module-name
require
module-name
&optional
pathname
Each module has a unique name (a string). The provide
and require
functions accept either a string or a symbol as
the module-name argument. If a symbol is provided, its print
name is used as the module name. If the module consists of a single
package, it is customary for the package and module names to be the
same.
The provide
function adds a new module name to the list
of modules maintained in the variable *modules*
, thereby
indicating that the module in question has been loaded.
The require
function tests whether a module is already
present (using a case-sensitive comparison); if the module is not
present, require
proceeds to load the appropriate file or
set of files. The pathname argument, if present, is a single
pathname or a list of pathnames whose files are to be loaded in order,
left to right. If the pathname argument is nil
or
is not provided, the system will attempt to determine, in some
system-dependent manner, which files to load. This will typically
involve some central registry of module names and the associated file
lists.
X3J13 voted in March 1988 not to permit symbols as pathnames
(PATHNAME-SYMBOL) and to specify exactly which streams may be used as
pathnames (PATHNAME-STREAM) (see section 23.1.6). Of course, this is
moot if require
is not in the language.
X3J13 voted in January 1989 (RETURN-VALUES-UNSPECIFIED) to specify
that the values returned by provide
and
require
are implementation-dependent. Of course, this is
moot if provide
and require
are not in the
language.
Implementation note: One way to implement such a registry on many operating systems is simply to use a distinguished ``library’’ directory within the file system, where the name of each file is the same as the module it contains.
Next: An Example
Up: Packages
Previous: Package System
Functions
AI.Repository@cs.cmu.edu