81 lines
4.9 KiB
HTML
81 lines
4.9 KiB
HTML
<!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>5.3. Top-Level Forms</TITLE>
|
|
</HEAD>
|
|
<BODY>
|
|
<meta name="description" value=" Top-Level Forms">
|
|
<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=tex2html2319 HREF="node66.html"><IMG ALIGN=BOTTOM ALT="next" SRC="icons/next_motif.gif"></A> <A NAME=tex2html2317 HREF="node55.html"><IMG ALIGN=BOTTOM ALT="up" SRC="icons/up_motif.gif"></A> <A NAME=tex2html2313 HREF="node64.html"><IMG ALIGN=BOTTOM ALT="previous" SRC="icons/previous_motif.gif"></A> <A NAME=tex2html2321 HREF="node1.html"><IMG ALIGN=BOTTOM ALT="contents" SRC="icons/contents_motif.gif"></A> <A NAME=tex2html2322 HREF="index.html"><IMG ALIGN=BOTTOM ALT="index" SRC="icons/index_motif.gif"></A> <BR>
|
|
<B> Next:</B> <A NAME=tex2html2320 HREF="node66.html"> Defining Named Functions</A>
|
|
<B>Up:</B> <A NAME=tex2html2318 HREF="node55.html"> Program Structure</A>
|
|
<B> Previous:</B> <A NAME=tex2html2314 HREF="node64.html"> Lambda-Expressions</A>
|
|
<HR> <P>
|
|
<H1><A NAME=SECTION00930000000000000000>5.3. Top-Level Forms</A></H1>
|
|
<P>
|
|
The standard way for the user to interact with a Common Lisp implementation is
|
|
via a <i>read-eval-print loop</i>: the system repeatedly
|
|
reads a form from some input source (such as a keyboard or a disk file),
|
|
evaluates it, and then prints the value(s) to some output sink (such as a
|
|
display screen or another disk file). Any form (evaluable
|
|
data object) is acceptable; however, certain special forms are specifically
|
|
designed to be convenient for use as <i>top-level</i> forms,
|
|
rather than as forms embedded within other forms in the way
|
|
that <tt>(+ 3 4)</tt>
|
|
is embedded within <tt>(if p (+ 3 4) 6)</tt>.
|
|
These top-level special forms may be used to define globally named
|
|
functions, to define macros, to make declarations,
|
|
and to define global values for special variables.
|
|
<P>
|
|
<img align=bottom alt="old_change_begin" src="gif/old_change_begin.gif"><br>
|
|
It is not illegal to use these forms at other than top level,
|
|
but whether it is meaningful to do so depends on context.
|
|
Compilers, for example, may not recognize these forms properly
|
|
in other than top-level contexts. (As a special case, however,
|
|
if a <tt>progn</tt> form appears at top level, then all forms
|
|
within that <tt>progn</tt> are considered by the compiler to be top-level
|
|
forms.)
|
|
<br><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 (DEFINING-MACROS-NON-TOP-LEVEL) <A NAME=3503> </A>
|
|
to clarify that, while defining forms normally appear at top level,
|
|
it is meaningful to place them in non-top-level contexts.
|
|
All defining forms that create functional objects from code appearing
|
|
as argument forms must ensure that
|
|
such argument forms refer to the enclosing lexical environment.
|
|
Compilers must handle defining forms properly in all situations,
|
|
not just top-level contexts. However, certain
|
|
compile-time side effects of these defining forms are performed only
|
|
when the defining forms occur at top level (see section <A HREF="node224.html#COMPILERSECTION">25.1</A>).
|
|
<br><img align=bottom alt="change_end" src="gif/change_end.gif">
|
|
<P>
|
|
<hr>
|
|
<b>Compatibility note:</b> In MacLisp, a top-level <tt>progn</tt> is considered to
|
|
contain top-level forms only if the first form is <tt>(quote compile)</tt>.
|
|
This odd marker is unnecessary in Common Lisp.
|
|
<hr>
|
|
<P>
|
|
Macros are usually defined by using the special form <tt>defmacro</tt>.
|
|
This facility is fairly complicated; it is described in chapter <A HREF="node97.html#MACROS">8</A>.
|
|
<P>
|
|
<HR>
|
|
<UL>
|
|
<LI> <A NAME=tex2html2323 HREF="node66.html#SECTION00931000000000000000"> Defining Named Functions</A>
|
|
<LI> <A NAME=tex2html2324 HREF="node67.html#SECTION00932000000000000000"> Declaring Global Variables and Named Constants</A>
|
|
<LI> <A NAME=tex2html2325 HREF="node68.html#SECTION00933000000000000000"> Control of Time of Evaluation</A>
|
|
</UL>
|
|
<BR> <HR><A NAME=tex2html2319 HREF="node66.html"><IMG ALIGN=BOTTOM ALT="next" SRC="icons/next_motif.gif"></A> <A NAME=tex2html2317 HREF="node55.html"><IMG ALIGN=BOTTOM ALT="up" SRC="icons/up_motif.gif"></A> <A NAME=tex2html2313 HREF="node64.html"><IMG ALIGN=BOTTOM ALT="previous" SRC="icons/previous_motif.gif"></A> <A NAME=tex2html2321 HREF="node1.html"><IMG ALIGN=BOTTOM ALT="contents" SRC="icons/contents_motif.gif"></A> <A NAME=tex2html2322 HREF="index.html"><IMG ALIGN=BOTTOM ALT="index" SRC="icons/index_motif.gif"></A> <BR>
|
|
<B> Next:</B> <A NAME=tex2html2320 HREF="node66.html"> Defining Named Functions</A>
|
|
<B>Up:</B> <A NAME=tex2html2318 HREF="node55.html"> Program Structure</A>
|
|
<B> Previous:</B> <A NAME=tex2html2314 HREF="node64.html"> Lambda-Expressions</A>
|
|
<HR> <P>
|
|
<HR>
|
|
<P><ADDRESS>
|
|
AI.Repository@cs.cmu.edu
|
|
</ADDRESS>
|
|
</BODY>
|