79 lines
2.3 KiB
HTML
79 lines
2.3 KiB
HTML
<!DOCTYPE HTML PUBLIC "-//W3O//DTD W3 HTML 2.0//EN">
|
|
<!Originally converted to HTML using LaTeX2HTML 95 (Thu Jan 19 1995) by Nikos Drakos (nikos@cbl.leeds.ac.uk), CBLU, University of Leeds >
|
|
<HEAD>
|
|
<TITLE> Lists</TITLE>
|
|
</HEAD>
|
|
<BODY>
|
|
<meta name="description" value=" Lists">
|
|
<meta name="keywords" value="lp">
|
|
<meta name="resource-type" value="document">
|
|
<meta name="distribution" value="global">
|
|
<P>
|
|
<BR> <HR>
|
|
<A HREF="node7.html"><IMG ALIGN=BOTTOM ALT="next" SRC="next_motif.gif"></A>
|
|
<A HREF="node4.html"><IMG ALIGN=BOTTOM ALT="up" SRC="up_motif.gif"></A>
|
|
<A HREF="node5.html"><IMG ALIGN=BOTTOM ALT="previous" SRC="previous_motif.gif"></A> <BR>
|
|
<A HREF="lp.html"><B>Contents</B></A>
|
|
<B> Next:</B>
|
|
<A HREF="node7.html"> Some Primitive Functions</A>
|
|
<B>Up:</B>
|
|
<A HREF="node4.html"> Basic Data Types</A>
|
|
<B> Previous:</B>
|
|
<A HREF="node5.html"> Atoms</A>
|
|
<BR> <HR> <P>
|
|
<H2> Lists</H2>
|
|
<P>
|
|
The second rule of evaluation concerns lists. The interpreter treats
|
|
any list as containing the name of a function followed by the
|
|
arguments to the function. Schematically then, a list is read like
|
|
this:
|
|
<P>
|
|
<BLOCKQUOTE>
|
|
<PRE>(name-of-function first-argument second-argument ...)
|
|
</PRE>
|
|
</BLOCKQUOTE>
|
|
For example, try the following:
|
|
<P>
|
|
<BLOCKQUOTE>
|
|
<PRE>> (+ 2 13 45)
|
|
60
|
|
</PRE>
|
|
</BLOCKQUOTE>
|
|
In this case, the interpreter applied the function + to the evaluated
|
|
arguments and return with the value 60. Since the numbers are
|
|
predefined, eval finds values for all the arguments, and everyone is
|
|
happy. You could also enter:
|
|
<P>
|
|
<BLOCKQUOTE>
|
|
<PRE>> (+ my-age 1)
|
|
11
|
|
</PRE>
|
|
</BLOCKQUOTE>
|
|
This works fine because my-age is evaluated and the value 10 is found
|
|
(assuming you did just what was described in the section above).
|
|
However:
|
|
<P>
|
|
<BLOCKQUOTE>
|
|
<PRE>> (+ your-age 1)
|
|
</PRE>
|
|
</BLOCKQUOTE>
|
|
will generate an error (unbound variable your-age).
|
|
<P>
|
|
Also, if you attempt to use something that is not a function, you
|
|
will generate an error message. So, for example, typing
|
|
<P>
|
|
<BLOCKQUOTE>
|
|
<PRE>> (foo 1 3 4)
|
|
</PRE>
|
|
</BLOCKQUOTE>
|
|
causes an error (undefined function foo), unless you had previously
|
|
defined foo to be a function. (More on defining functions in a later
|
|
chapter).
|
|
<P>
|
|
<BR> <HR>
|
|
<P>
|
|
<ADDRESS>
|
|
<I>© Colin Allen & Maneesh Dhagat <BR>
|
|
March 2007 </I>
|
|
</ADDRESS>
|
|
</BODY>
|