emacs.d/clones/lisp/colinallen.dnsalias.org/lp/node69.html

56 lines
1.7 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> Mapcar</TITLE>
</HEAD>
<BODY>
<meta name="description" value=" Mapcar">
<meta name="keywords" value="lp">
<meta name="resource-type" value="document">
<meta name="distribution" value="global">
<P>
<BR> <HR>
<A HREF="node70.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="node68.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="node70.html"> Backquote and Commas</A>
<B>Up:</B>
<A HREF="node64.html"> FunctionsLambda Expressions, </A>
<B> Previous:</B>
<A HREF="node68.html"> Apply</A>
<BR> <HR> <P>
<H1>Mapcar</H1>
<P>
<font size=-1><em>[We are grateful to <a
href="mailto:remmers@jremmers.org">John H. Remmers</a> for allowing
material from his <a
href="http://www.emunix.emich.edu/~remmers/337/lisp-functional-features.html">programming
languages course</a> to be incorporated into this
section.]</em></font>
<P>The <TT>MAPCAR</TT> form is an &quot;iterator&quot; that applies a
function repeatedly, to each element of a list and returns a list of the results. For example:
<BLOCKQUOTE>
<TT>&gt; (mapcar 'atom '(dog (cat horse) fish))<br>
(t nil t)
</TT></BLOCKQUOTE>
<BLOCKQUOTE><TT>
<TT>&gt; (mapcar (lambda (x) (* x x)) '(4 7 2 9))<br>
(16 49 4 81)
</TT></BLOCKQUOTE>
<BR> <HR>
<P>
<ADDRESS>
<I>&#169; Colin Allen, John H. Remmers, &amp; Maneesh Dhagat <BR>
March 2007 </I>
</ADDRESS>
</BODY>