64 lines
1.8 KiB
HTML
64 lines
1.8 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> Lambda Expressions</TITLE>
|
||
|
</HEAD>
|
||
|
<BODY>
|
||
|
<meta name="description" value=" Lambda Expressions">
|
||
|
<meta name="keywords" value="lp">
|
||
|
<meta name="resource-type" value="document">
|
||
|
<meta name="distribution" value="global">
|
||
|
<P>
|
||
|
<BR> <HR>
|
||
|
<A HREF="node67.html"><IMG ALIGN=BOTTOM ALT="next" SRC="next_motif.gif"></A>
|
||
|
<A HREF="node64.html"><IMG ALIGN=BOTTOM ALT="up" SRC="up_motif.gif"></A>
|
||
|
<A HREF="node65.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="node67.html"> Funcall</A>
|
||
|
<B>Up:</B>
|
||
|
<A HREF="node64.html"> FunctionsLambda Expressions, </A>
|
||
|
<B> Previous:</B>
|
||
|
<A HREF="node65.html"> Eval</A>
|
||
|
<BR> <HR> <P>
|
||
|
<H1> Lambda Expressions</H1>
|
||
|
|
||
|
The Lambda Expression is the heart of Lisp's notion of a function.
|
||
|
The term comes from Alonzo Church's ``lambda calculus'' -- a
|
||
|
development of mathematical logic. You can think of a lambda
|
||
|
expression as an anonymous function. Just like a function it has a
|
||
|
list of parameters and a block of code specifying operations on those
|
||
|
parameters.
|
||
|
|
||
|
<p>
|
||
|
For example:
|
||
|
<pre>
|
||
|
> (setf product '(lambda (x y) (* x y)))
|
||
|
(LAMBDA (X Y) (* X Y))
|
||
|
> product
|
||
|
(LAMBDA (X Y) (* X Y))
|
||
|
</pre>
|
||
|
|
||
|
Note that in some recent versions of Common Lisp, the lambda
|
||
|
expression should be unquoted, or the next step will not work.
|
||
|
<br>Use <tt>(setf product (lambda (x y) (* x y)))</tt> instead.
|
||
|
|
||
|
<p>
|
||
|
Lambda expressions can be used in conjunction with <a
|
||
|
href="node68.html">apply</a> to mimic function calls:
|
||
|
<pre>
|
||
|
> (apply product '(3 4))
|
||
|
12
|
||
|
</pre>
|
||
|
|
||
|
|
||
|
|
||
|
<P>
|
||
|
<BR> <HR>
|
||
|
<P>
|
||
|
<ADDRESS>
|
||
|
<I>© Colin Allen & Maneesh Dhagat <BR>
|
||
|
March 2007 </I>
|
||
|
</ADDRESS>
|
||
|
</BODY>
|