File: LISP-tutorial-9.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,276 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: Forms and the Top-Level Loop</TITLE>
</HEAD>
<BODY>
<A HREF="LISP-tutorial-8.html"><IMG SRC="prev.gif" ALT="Previous"></A>
<A HREF="LISP-tutorial-10.html"><IMG SRC="next.gif" ALT="Next"></A>
<A HREF="LISP-tutorial.html#toc9"><IMG SRC="toc.gif" ALT="Contents"></A>
<HR>
<H2><A NAME="s9">9. Forms and the Top-Level Loop</A></H2>

<P>The things which you type to the LISP interpreter are called forms; the
LISP interpreter repeatedly reads a form, evaluates it, and prints the
result. This procedure is called the read-eval-print loop.</P>
<P>Some forms will cause errors. After an error, LISP will put you into
the debugger so you can try to figure out what caused the error. LISP
debuggers are all different; but most will respond to the command
"help" or ":help" by giving some form of help.</P>
<P>In general, a form is either an atom (for example, a symbol, an
integer, or a string) or a list. If the form is an atom, LISP evaluates
it immediately. Symbols evaluate to their value; integers and strings
evaluate to themselves. If the form is a list, LISP treats its first
element as the name of a function; it evaluates the remaining elements
recursively, and then calls the function with the values of the
remaining elements as arguments.</P>
<P>For example, if LISP sees the form <CODE>(+ 3 4)</CODE>, it treats <CODE>+</CODE> as
the name of 
a function. It then evaluates 3 to get 3 and 4 to get 4; finally it
calls <CODE>+</CODE> with 3 and 4 as the arguments. The <CODE>+</CODE> function
returns 7, which 
LISP prints.</P>
<P>The top-level loop provides some other conveniences; one particularly
convenient convenience is the ability to talk about the results of
previously typed forms. LISP always saves its most recent three
results; it stores them as the values of the symbols <CODE>*</CODE>, <CODE>**</CODE>,
and <CODE>***</CODE>. 
For example:</P>
<P>
<BLOCKQUOTE><CODE>
<PRE>
&gt; 3
3
&gt; 4
4
&gt; 5
5
&gt; ***
3
&gt; ***
4
&gt; ***
5
&gt; **
4
&gt; *
4
</PRE>
</CODE></BLOCKQUOTE>
</P>


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