emacs.d/clones/lisp/www.cs.cmu.edu/Groups/AI/html/cltl/clm/node117.html

211 lines
11 KiB
HTML
Raw Normal View History

2022-08-26 19:11:35 +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.6. Built-in Packages</TITLE>
</HEAD>
<BODY>
<meta name="description" value=" Built-in Packages">
<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=tex2html2983 HREF="node118.html"><IMG ALIGN=BOTTOM ALT="next" SRC="icons/next_motif.gif"></A> <A NAME=tex2html2981 HREF="node111.html"><IMG ALIGN=BOTTOM ALT="up" SRC="icons/up_motif.gif"></A> <A NAME=tex2html2975 HREF="node116.html"><IMG ALIGN=BOTTOM ALT="previous" SRC="icons/previous_motif.gif"></A> <A NAME=tex2html2985 HREF="node1.html"><IMG ALIGN=BOTTOM ALT="contents" SRC="icons/contents_motif.gif"></A> <A NAME=tex2html2986 HREF="index.html"><IMG ALIGN=BOTTOM ALT="index" SRC="icons/index_motif.gif"></A> <BR>
<B> Next:</B> <A NAME=tex2html2984 HREF="node118.html"> Package System Functions </A>
<B>Up:</B> <A NAME=tex2html2982 HREF="node111.html"> Packages</A>
<B> Previous:</B> <A NAME=tex2html2976 HREF="node116.html"> Name Conflicts</A>
<HR> <P>
<H1><A NAME=SECTION001560000000000000000>11.6. Built-in Packages</A></H1>
<P>
<img align=bottom alt="old_change_begin" src="gif/old_change_begin.gif"><br>
The following packages, at least, are built into every Common Lisp system.
<P>
<DL COMPACT><DT><tt>lisp</tt>
<DD>
The package named <tt>lisp</tt> contains the primitives of the
Common Lisp system. Its external symbols include all of the
user-visible functions and global variables that are present in the
Common Lisp system, such as <tt>car</tt>, <tt>cdr</tt>, and <tt>*package*</tt>.
Almost all other packages will want to use <tt>lisp</tt> so that these
symbols will be accessible without qualification.
<P>
<DT><tt>user</tt>
<DD>
The <tt>user</tt> package is, by default, the current package at the time
a Common Lisp system starts up. This package uses the <tt>lisp</tt> package.
</DL>
<img align=bottom alt="old_change_end" src="gif/old_change_end.gif">
<P>
<img align=bottom alt="change_begin" src="gif/change_begin.gif"><br>
X3J13 voted in March 1989 (LISP-PACKAGE-NAME) <A NAME=10403>&#160;</A> to specify that
the forthcoming ANSI Common Lisp will use the package name <tt>common-lisp</tt>
instead of <tt>lisp</tt> and the package name <tt>common-lisp-user</tt>
instead of <tt>user</tt>. The purpose is to allow a single Lisp system
to support both ``old'' Common Lisp and ``new'' ANSI Common Lisp
simultaneously despite the fact that in some cases
the two languages use the same
names for incompatible purposes. (That's what packages are for!)
<P>
<DL COMPACT><DT><tt>common-lisp</tt>
<DD>
The package named <tt>common-lisp</tt> contains the primitives of the
ANSI Common Lisp system (as opposed to a Common Lisp system based
on the 1984 specification). Its external symbols include all of the
user-visible functions and global variables that are present in the
ANSI Common Lisp system, such as <tt>car</tt>, <tt>cdr</tt>, and <tt>*package*</tt>.
Note, however, that the home package of such symbols is not
necessarily the <tt>common-lisp</tt> package (this makes it easier for
symbols such as <tt>t</tt> and <tt>lambda</tt> to be shared between
the <tt>common-lisp</tt> package and another package, possibly one named <tt>lisp</tt>).
Almost all other packages ought to use <tt>common-lisp</tt> so that these
symbols will be accessible without qualification.
This package has the nickname <tt>cl</tt>.
<P>
<DT><tt>common-lisp-user</tt>
<DD>
The <tt>common-lisp-user</tt> package is, by default,
the current package at the time an ANSI Common Lisp system starts up.
This package uses the <tt>common-lisp</tt> package
and has the nickname <tt>cl-user</tt>.
It may contain other implementation-dependent symbols
and may use other implementation-specific packages.
</DL>
<img align=bottom alt="change_end" src="gif/change_end.gif">
<P>
<DL COMPACT><DT><tt>keyword</tt>
<DD>
This package contains all of the keywords used by built-in
or user-defined Lisp functions. Printed symbol representations
that start with a colon are interpreted as referring to symbols
in this package, which are always external symbols. All symbols in this
package are treated as constants that evaluate to themselves, so that the
user can type <tt>:foo</tt> instead of <tt>':foo</tt>.
<P>
</DL>
<P>
<img align=bottom alt="old_change_begin" src="gif/old_change_begin.gif"><br>
<DL COMPACT><DT><tt>system</tt>
<DD>
This package name is reserved to the implementation.
Normally this is used to contain names of implementation-dependent
system-interface functions. This package uses <tt>lisp</tt> and has the
nickname <tt>sys</tt>.
</DL>
<img align=bottom alt="old_change_end" src="gif/old_change_end.gif">
<P>
<img align=bottom alt="change_begin" src="gif/change_begin.gif"><br>
X3J13 voted in January 1989
(PACKAGE-CLUTTER) <A NAME=10440>&#160;</A>
to modify the requirements on the built-in packages
so as to limit what may appear in the <tt>common-lisp</tt> package
and to lift the requirement that every implementation have a package
named <tt>system</tt>. The details are as follows.
<P>
Not only must the <tt>common-lisp</tt> package in any given implementation
contain all the external symbols prescribed by the standard;
the <tt>common-lisp</tt> package moreover may not contain any external symbol
that is not prescribed by the standard. However, the <tt>common-lisp</tt>
package may contain additional internal symbols, depending on the
implementation.
<P>
An external symbol of the <tt>common-lisp</tt> package may not have a function,
macro, or special form definition, or a top-level value,
or a <tt>special</tt> proclamation, or a type definition, unless specifically
permitted by the standard. Programmers may validly rely on this fact;
for example, <tt>fboundp</tt> is guaranteed to be false for all
external symbols of the <tt>common-lisp</tt> package except those explicitly
specified in the standard to name functions, macros, and special forms.
Similarly, <tt>boundp</tt> will be false of all such external symbols
except those documented to be variables or constants.
<P>
Portable programs
may use external symbols in the <tt>common-lisp</tt> package that are not documented
to be constants or variables as names of local lexical
variables with the presumption that the implementation has not
proclaimed such variables to be special; this legitimizes the common
practice of using such names as <tt>list</tt> and <tt>string</tt> as names
for local variables.
<P>
A valid implementation may initially have properties on any symbol,
or dynamically put new properties on symbols (even user-created symbols),
as long as no property indicator used for this purpose is
an external symbol of any package defined by the standard
or a symbol that is accessible from the <tt>common-lisp-user</tt> package or any
package defined by the user.
<P>
This vote eliminates the requirement that every implementation have
a predefined package named <tt>system</tt>. An implementation may
provide any number of predefined packages; these should be described
in the documentation for that implementation.
<P>
The <tt>common-lisp-user</tt> package may contain symbols not described by the standard
and may use other implementation-specific packages.
<P>
X3J13 voted in March 1989 (LISP-SYMBOL-REDEFINITION) <A NAME=10459>&#160;</A>
to restrict user programs from performing certain actions that
might interfere with built-in facilities or interact badly
with them.
Except where explicitly allowed, the consequences are undefined if any
of the following actions are performed on a symbol in the <tt>common-lisp</tt>
package.
<UL><LI> binding or altering its value (lexically or dynamically)
<LI> defining or binding it as a function
<LI> defining or binding it as a macro
<LI> defining it as a type specifier (<tt>defstruct</tt>, <tt>defclass</tt>, <tt>deftype</tt>)
<LI> defining it as a structure (<tt>defstruct</tt>)
<LI> defining it as a declaration
<LI> dsing it as a symbol macro
<LI> altering its print name
<LI> altering its package
<LI> tracing it
<LI> declaring or proclaiming it special or lexical
<LI> declaring or proclaiming its <tt>type</tt> or <tt>ftype</tt>
<LI> removing it from the package <tt>common-lisp</tt>
</UL>
X3J13 also voted in June 1989 (DEFINE-COMPILER-MACRO) <A NAME=10470>&#160;</A>
to add to this list the item
<UL><LI> defining it as a compiler macro
</UL>
<P>
If such a symbol is not globally defined as a variable or a constant,
a user program is allowed to lexically bind it and declare the <tt>type</tt> of that binding.
<P>
If such a symbol is not defined as a function, macro, or special form,
a user program is allowed to (lexically) bind it as a function and to declare the
<tt>ftype</tt> of that binding and to trace that binding.
<P>
If such a symbol is not defined as a function, macro, or special form,
a user program is allowed to (lexically) bind it as a macro.
<P>
As an example, the behavior of the code fragment
<P><pre>
(flet ((open (filename &amp;key direction)
(format t &quot;~%OPEN was called.&quot;)
(open filename :direction direction)))
(with-open-file (x &quot;frob&quot; :direction ':output)
(format t &quot;~%Was OPEN called?&quot;)))
</pre><P>
is undefined. Even in a ``reasonable'' implementation,
for example, the macro expansion of <tt>with-open-file</tt> might refer
to the <tt>open</tt> function and might not. However, the preceding rules eliminate
the burden of deciding whether an implementation is reasonable. The code
fragment violates the rules; officially its behavior is therefore
completely undefined, and that's that.
<P>
Note that ``altering the property list'' is not in the list of
proscribed actions, so a user program <i>is</i> permitted to
add properties to or remove properties from
symbols in the <tt>common-lisp</tt> package.
<br><img align=bottom alt="change_end" src="gif/change_end.gif">
<P>
<BR> <HR><A NAME=tex2html2983 HREF="node118.html"><IMG ALIGN=BOTTOM ALT="next" SRC="icons/next_motif.gif"></A> <A NAME=tex2html2981 HREF="node111.html"><IMG ALIGN=BOTTOM ALT="up" SRC="icons/up_motif.gif"></A> <A NAME=tex2html2975 HREF="node116.html"><IMG ALIGN=BOTTOM ALT="previous" SRC="icons/previous_motif.gif"></A> <A NAME=tex2html2985 HREF="node1.html"><IMG ALIGN=BOTTOM ALT="contents" SRC="icons/contents_motif.gif"></A> <A NAME=tex2html2986 HREF="index.html"><IMG ALIGN=BOTTOM ALT="index" SRC="icons/index_motif.gif"></A> <BR>
<B> Next:</B> <A NAME=tex2html2984 HREF="node118.html"> Package System Functions </A>
<B>Up:</B> <A NAME=tex2html2982 HREF="node111.html"> Packages</A>
<B> Previous:</B> <A NAME=tex2html2976 HREF="node116.html"> Name Conflicts</A>
<HR> <P>
<HR>
<P><ADDRESS>
AI.Repository@cs.cmu.edu
</ADDRESS>
</BODY>