1
0
Fork 0
cl-sites/www.cs.cmu.edu/Groups/AI/html/cltl/clm/node119.html

101 lines
5.7 KiB
HTML
Raw Normal View History

2023-10-25 11:23:21 +02:00
<!DOCTYPE HTML PUBLIC "-//W3O//DTD W3 HTML 2.0//EN">
<!Converted with LaTeX2HTML 0.6.5 (Tue Nov 15 1994) by Nikos Drakos (nikos@cbl.leeds.ac.uk), CBLU, University of Leeds >
<HEAD>
<TITLE>11.8. Modules</TITLE>
</HEAD>
<BODY>
<meta name="description" value=" Modules">
<meta name="keywords" value="clm">
<meta name="resource-type" value="document">
<meta name="distribution" value="global">
<P>
<b>Common Lisp the Language, 2nd Edition</b>
<BR> <HR><A NAME=tex2html3007 HREF="node120.html"><IMG ALIGN=BOTTOM ALT="next" SRC="icons/next_motif.gif"></A> <A NAME=tex2html3005 HREF="node111.html"><IMG ALIGN=BOTTOM ALT="up" SRC="icons/up_motif.gif"></A> <A NAME=tex2html2999 HREF="node118.html"><IMG ALIGN=BOTTOM ALT="previous" SRC="icons/previous_motif.gif"></A> <A NAME=tex2html3009 HREF="node1.html"><IMG ALIGN=BOTTOM ALT="contents" SRC="icons/contents_motif.gif"></A> <A NAME=tex2html3010 HREF="index.html"><IMG ALIGN=BOTTOM ALT="index" SRC="icons/index_motif.gif"></A> <BR>
<B> Next:</B> <A NAME=tex2html3008 HREF="node120.html"> An Example</A>
<B>Up:</B> <A NAME=tex2html3006 HREF="node111.html"> Packages</A>
<B> Previous:</B> <A NAME=tex2html3000 HREF="node118.html"> Package System Functions </A>
<HR> <P>
<H1><A NAME=SECTION001580000000000000000>11.8. Modules</A></H1>
<P>
A <i>module</i> 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.
<P>
<img align=bottom alt="change_begin" src="gif/change_begin.gif"><br>
X3J13 voted in January 1989
(REQUIRE-PATHNAME-DEFAULTS) <A NAME=11096>&#160;</A>
to eliminate the entire module facility from
the language; that is, the variable <tt>*modules*</tt> and the functions
<tt>provide</tt> and <tt>require</tt> are deleted.
X3J13 commented that the file-loading feature of <tt>require</tt> is not
portable, and that the remaining functionality is easily implemented
by user code. (I will add that in any case the specification of
<tt>require</tt> is so vague that different implementations are likely to
have differing behavior.)
<br><img align=bottom alt="change_end" src="gif/change_end.gif">
<P>
<BR><b>[Variable]</b><BR>
<tt>*modules*</tt><P>The variable <tt>*modules*</tt> 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 <tt>provide</tt> and <tt>require</tt>.
<P>
<BR><b>[Function]</b><BR>
<tt>provide</tt> <tt><i>module-name</i></tt> <tt><BR></tt><tt>require</tt> <tt><i>module-name</i></tt> <tt>&amp;optional</tt> <tt><i>pathname</i></tt><P>Each module has a unique name (a string). The <tt>provide</tt> and <tt>require</tt>
functions accept either a string or a symbol as the <i>module-name</i>
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.
<P>
The <tt>provide</tt>
function adds a new module name to the list of modules
maintained in the variable <tt>*modules*</tt>, thereby indicating that
the module in question has been loaded.
<P>
The <tt>require</tt> function tests whether a module is already present
(using a case-sensitive comparison); if the module is not present,
<tt>require</tt> proceeds to load the appropriate
file or set of files. The <i>pathname</i> 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 <i>pathname</i> argument is <tt>nil</tt> 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.
<P>
<img align=bottom alt="change_begin" src="gif/change_begin.gif"><br>
X3J13 voted in March 1988
not to permit symbols as pathnames
(PATHNAME-SYMBOL) <A NAME=11120>&#160;</A> and
to specify exactly which streams may be used as pathnames
(PATHNAME-STREAM) <A NAME=11121>&#160;</A> (see section <A HREF="node214.html#PATHNAMEFUNCTIONS">23.1.6</A>).
Of course, this is moot if <tt>require</tt> is not in the language.
<P>
X3J13 voted in January 1989
(RETURN-VALUES-UNSPECIFIED) <A NAME=11126>&#160;</A>
to specify that the values returned by <tt>provide</tt> and <tt>require</tt>
are implementation-dependent. Of course, this is moot
if <tt>provide</tt> and <tt>require</tt> are not in the language.
<br><img align=bottom alt="change_end" src="gif/change_end.gif">
<P>
<hr>
<b>Implementation note:</b> 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.
<hr>
<P>
<BR> <HR><A NAME=tex2html3007 HREF="node120.html"><IMG ALIGN=BOTTOM ALT="next" SRC="icons/next_motif.gif"></A> <A NAME=tex2html3005 HREF="node111.html"><IMG ALIGN=BOTTOM ALT="up" SRC="icons/up_motif.gif"></A> <A NAME=tex2html2999 HREF="node118.html"><IMG ALIGN=BOTTOM ALT="previous" SRC="icons/previous_motif.gif"></A> <A NAME=tex2html3009 HREF="node1.html"><IMG ALIGN=BOTTOM ALT="contents" SRC="icons/contents_motif.gif"></A> <A NAME=tex2html3010 HREF="index.html"><IMG ALIGN=BOTTOM ALT="index" SRC="icons/index_motif.gif"></A> <BR>
<B> Next:</B> <A NAME=tex2html3008 HREF="node120.html"> An Example</A>
<B>Up:</B> <A NAME=tex2html3006 HREF="node111.html"> Packages</A>
<B> Previous:</B> <A NAME=tex2html3000 HREF="node118.html"> Package System Functions </A>
<HR> <P>
<HR>
<P><ADDRESS>
AI.Repository@cs.cmu.edu
</ADDRESS>
</BODY>