86 lines
4.7 KiB
HTML
86 lines
4.7 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.1.3. Special Forms</TITLE>
|
||
|
</HEAD>
|
||
|
<BODY>
|
||
|
<meta name="description" value=" Special 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=tex2html2251 HREF="node60.html"><IMG ALIGN=BOTTOM ALT="next" SRC="icons/next_motif.gif"></A> <A NAME=tex2html2249 HREF="node56.html"><IMG ALIGN=BOTTOM ALT="up" SRC="icons/up_motif.gif"></A> <A NAME=tex2html2243 HREF="node58.html"><IMG ALIGN=BOTTOM ALT="previous" SRC="icons/previous_motif.gif"></A> <A NAME=tex2html2253 HREF="node1.html"><IMG ALIGN=BOTTOM ALT="contents" SRC="icons/contents_motif.gif"></A> <A NAME=tex2html2254 HREF="index.html"><IMG ALIGN=BOTTOM ALT="index" SRC="icons/index_motif.gif"></A> <BR>
|
||
|
<B> Next:</B> <A NAME=tex2html2252 HREF="node60.html"> Macros</A>
|
||
|
<B>Up:</B> <A NAME=tex2html2250 HREF="node56.html"> Forms</A>
|
||
|
<B> Previous:</B> <A NAME=tex2html2244 HREF="node58.html"> Variables</A>
|
||
|
<HR> <P>
|
||
|
<H2><A NAME=SECTION00913000000000000000>5.1.3. Special Forms</A></H2>
|
||
|
<P>
|
||
|
If a list is to be evaluated as a form, the first step is to examine
|
||
|
the first element of the list. If the first element is one of
|
||
|
the symbols appearing in table <A HREF="node59.html#SPECIALFORMTABLE">5-1</A>,
|
||
|
then the list is called a <i>special form</i>. (This use of the word
|
||
|
``special'' is unrelated to its use in the phrase ``special variable.'')
|
||
|
<P>
|
||
|
Special forms are generally environment and control constructs.
|
||
|
Every special form has its own idiosyncratic syntax. An example
|
||
|
is the <tt>if</tt> special form:
|
||
|
<tt>(if p (+ x 4) 5)</tt> in Common Lisp means what
|
||
|
``<b>if</b> <i>p</i> <b>then</b> <i>x</i>+4 <b>else</b> 5'' means in Algol.
|
||
|
<P>
|
||
|
The evaluation of a special form normally produces a value or values,
|
||
|
but the evaluation may instead call for a non-local exit; see <tt>return-from</tt>,
|
||
|
<tt>go</tt>, and <tt>throw</tt>.
|
||
|
<P>
|
||
|
The set of special forms is fixed in Common Lisp; no way is provided
|
||
|
for the user to define more. The user can create new syntactic
|
||
|
constructs, however, by defining macros.
|
||
|
<P>
|
||
|
The set of special forms in Common Lisp is purposely kept very small
|
||
|
because any program-analyzing program must have special knowledge
|
||
|
about every type of special form. Such a program needs no special
|
||
|
knowledge about macros because it is simple to expand the macro
|
||
|
and operate on the resulting expansion. (This is not to say that
|
||
|
many such programs, particularly compilers, will not have such
|
||
|
special knowledge. A compiler may be able
|
||
|
to produce much better code if it recognizes such constructs
|
||
|
as <tt>typecase</tt> and <tt>multiple-value-bind</tt> and gives them customized
|
||
|
treatment.)
|
||
|
<P>
|
||
|
<A NAME=SPECIALFORMTABLE> </A><IMG ALIGN=BOTTOM ALT="" SRC="_24769_table3064.gif">
|
||
|
<P>
|
||
|
An implementation is free to implement as a macro any construct described
|
||
|
herein as a special form. Conversely, an implementation is free
|
||
|
to implement as a special form any construct described herein as a macro
|
||
|
if an equivalent macro definition is also provided.
|
||
|
The practical consequence is that the predicates <tt>macro-function</tt> and
|
||
|
<tt>special-form-p</tt> may both be true of the same symbol.
|
||
|
It is recommended that a program-analyzing program process
|
||
|
a form that is a list whose <i>car</i> is a symbol as follows:
|
||
|
<OL><LI>
|
||
|
If the program has particular knowledge about the symbol,
|
||
|
process the form using special-purpose code.
|
||
|
All of the symbols listed in table <A HREF="node59.html#SPECIALFORMTABLE">5-1</A>
|
||
|
should fall into this category.
|
||
|
<P>
|
||
|
<LI>
|
||
|
Otherwise, if <tt>macro-function</tt> is true of the symbol, apply either
|
||
|
<tt>macroexpand</tt> or <tt>macroexpand-1</tt>, as appropriate,
|
||
|
to the entire form and then start over.
|
||
|
<P>
|
||
|
<LI>
|
||
|
Otherwise, assume it is a function call.
|
||
|
</OL>
|
||
|
<P>
|
||
|
<BR> <HR><A NAME=tex2html2251 HREF="node60.html"><IMG ALIGN=BOTTOM ALT="next" SRC="icons/next_motif.gif"></A> <A NAME=tex2html2249 HREF="node56.html"><IMG ALIGN=BOTTOM ALT="up" SRC="icons/up_motif.gif"></A> <A NAME=tex2html2243 HREF="node58.html"><IMG ALIGN=BOTTOM ALT="previous" SRC="icons/previous_motif.gif"></A> <A NAME=tex2html2253 HREF="node1.html"><IMG ALIGN=BOTTOM ALT="contents" SRC="icons/contents_motif.gif"></A> <A NAME=tex2html2254 HREF="index.html"><IMG ALIGN=BOTTOM ALT="index" SRC="icons/index_motif.gif"></A> <BR>
|
||
|
<B> Next:</B> <A NAME=tex2html2252 HREF="node60.html"> Macros</A>
|
||
|
<B>Up:</B> <A NAME=tex2html2250 HREF="node56.html"> Forms</A>
|
||
|
<B> Previous:</B> <A NAME=tex2html2244 HREF="node58.html"> Variables</A>
|
||
|
<HR> <P>
|
||
|
<HR>
|
||
|
<P><ADDRESS>
|
||
|
AI.Repository@cs.cmu.edu
|
||
|
</ADDRESS>
|
||
|
</BODY>
|