58 lines
1.8 KiB
HTML
58 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> Apply</TITLE>
|
|
</HEAD>
|
|
<BODY>
|
|
<meta name="description" value=" Apply">
|
|
<meta name="keywords" value="lp">
|
|
<meta name="resource-type" value="document">
|
|
<meta name="distribution" value="global">
|
|
<P>
|
|
<BR> <HR>
|
|
<A HREF="node69.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="node67.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="node69.html"> Mapcar</A>
|
|
<B>Up:</B>
|
|
<A HREF="node64.html"> FunctionsLambda Expressions, </A>
|
|
<B> Previous:</B>
|
|
<A HREF="node67.html"> Funcall</A>
|
|
<BR> <HR> <P>
|
|
<H1> Apply</H1>
|
|
<P>
|
|
|
|
Apply takes its first argument and applies it as a function to the
|
|
list of items making up the last. For example:
|
|
|
|
<pre>
|
|
>(apply '* '(1 2 3 4))
|
|
24
|
|
</pre>
|
|
|
|
You can imagine this being obtained by constructing the list <tt>(* 1
|
|
2 3 4)</tt> and evaluating the resulting list, although this is not
|
|
strictly what happens since <tt>apply</tt> is a function, not a <a
|
|
href="node71.html">macro</a>. Apply also allows intermediate arguments
|
|
between the first and the last (see <a href="node81.html">appendix</a>)
|
|
but the last argument is required to be a list.
|
|
|
|
<p>
|
|
Apply can also be used in conjunction with lambda lists. For example:
|
|
<pre>
|
|
>(apply '(lambda (x y) (* x y)) '(45 67))
|
|
3015
|
|
</pre>
|
|
|
|
If this does not seem particularly useful to you, think about how it
|
|
can be used to construct complex programs on the fly.
|
|
|
|
<BR> <HR>
|
|
<P>
|
|
<ADDRESS>
|
|
<I>© Colin Allen & Maneesh Dhagat <BR>
|
|
May 1999</I>
|
|
</ADDRESS>
|
|
</BODY>
|