File: LISP-tutorial-10.html

package info (click to toggle)
cmucl 20c-2
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 42,524 kB
  • sloc: lisp: 358,331; ansic: 28,385; asm: 3,777; sh: 1,236; makefile: 366; csh: 31
file content (67 lines) | stat: -rw-r--r-- 2,087 bytes parent folder | download | duplicates (12)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<HTML>
<HEAD>
<TITLE>Common LISP Hints: Special forms</TITLE>
</HEAD>
<BODY>
<A HREF="LISP-tutorial-9.html"><IMG SRC="prev.gif" ALT="Previous"></A>
<A HREF="LISP-tutorial-11.html"><IMG SRC="next.gif" ALT="Next"></A>
<A HREF="LISP-tutorial.html#toc10"><IMG SRC="toc.gif" ALT="Contents"></A>
<HR>
<H2><A NAME="s10">10. Special forms</A></H2>

<P>There are a number of special forms which look like function calls but
aren't. These include control constructs such as <CODE>if</CODE> statements and do
loops; assignments like <CODE>setq</CODE>, <CODE>setf</CODE>, <CODE>push</CODE>, and <CODE>pop</CODE>;
definitions such as 
<CODE>defun</CODE> and <CODE>defstruct</CODE>; and binding constructs such as
<CODE>let</CODE>. (Not all of 
these special forms have been mentioned yet. See below.)</P>
<P>One useful special form is the <CODE>quote</CODE> form: <CODE>quote</CODE> prevents
its argument 
from being evaluated. For example:</P>
<P>
<BLOCKQUOTE><CODE>
<PRE>
&gt; (setq a 3)
3
&gt; a
3
&gt; (quote a)
A
&gt; 'a                    ;'a is an abbreviation for (quote a)
                        ;it's the quote next to the enter key
                        ;on a qwerty keyboard
A
</PRE>
</CODE></BLOCKQUOTE>
</P>
<P>Another similar special form is the <CODE>function</CODE> form: <CODE>function</CODE>
causes its 
argument to be interpreted as a function rather than being evaluated.
For example:</P>
<P>
<BLOCKQUOTE><CODE>
<PRE>
&gt; (setq + 3)
3
&gt; +
3
&gt; '+
+
&gt; (function +)
#&lt;Function + @ #x-fbef9de&gt;
&gt; #'+                   ;#'+ is an abbreviation for (function +)
#&lt;Function + @ #x-fbef9de&gt;
</PRE>
</CODE></BLOCKQUOTE>
</P>
<P>The <CODE>function</CODE> special form is useful when you want to pass a function as
an argument to another function. See below for some examples of
functions which take functions as arguments.</P>

<HR>
<A HREF="LISP-tutorial-9.html"><IMG SRC="prev.gif" ALT="Previous"></A>
<A HREF="LISP-tutorial-11.html"><IMG SRC="next.gif" ALT="Next"></A>
<A HREF="LISP-tutorial.html#toc10"><IMG SRC="toc.gif" ALT="Contents"></A>
</BODY>
</HTML>