1
0
Fork 0
cl-sites/www.cs.cmu.edu/Groups/AI/html/cltl/clm/node100.html
2023-10-25 11:23:21 +02:00

50 lines
2.7 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3O//DTD W3 HTML 2.0//EN">
<!Converted with LaTeX2HTML 0.6.5 (Tue Nov 15 1994) by Nikos Drakos (nikos@cbl.leeds.ac.uk), CBLU, University of Leeds >
<HEAD>
<TITLE>8.3. Destructuring</TITLE>
</HEAD>
<BODY>
<meta name="description" value=" Destructuring">
<meta name="keywords" value="clm">
<meta name="resource-type" value="document">
<meta name="distribution" value="global">
<P>
<b>Common Lisp the Language, 2nd Edition</b>
<BR> <HR><A NAME=tex2html2770 HREF="node101.html"><IMG ALIGN=BOTTOM ALT="next" SRC="icons/next_motif.gif"></A> <A NAME=tex2html2768 HREF="node97.html"><IMG ALIGN=BOTTOM ALT="up" SRC="icons/up_motif.gif"></A> <A NAME=tex2html2762 HREF="node99.html"><IMG ALIGN=BOTTOM ALT="previous" SRC="icons/previous_motif.gif"></A> <A NAME=tex2html2772 HREF="node1.html"><IMG ALIGN=BOTTOM ALT="contents" SRC="icons/contents_motif.gif"></A> <A NAME=tex2html2773 HREF="index.html"><IMG ALIGN=BOTTOM ALT="index" SRC="icons/index_motif.gif"></A> <BR>
<B> Next:</B> <A NAME=tex2html2771 HREF="node101.html"> Compiler Macros</A>
<B>Up:</B> <A NAME=tex2html2769 HREF="node97.html"> Macros</A>
<B> Previous:</B> <A NAME=tex2html2763 HREF="node99.html"> Macro Expansion</A>
<HR> <P>
<H1><A NAME=SECTION001230000000000000000>8.3. Destructuring</A></H1>
<P>
<img align=bottom alt="change_begin" src="gif/change_begin.gif"><br>
X3J13 voted in March 1989 (DESTRUCTURING-BIND) <A NAME=8600>&#160;</A>
to make the destructuring feature of <tt>defmacro</tt>
available as a separate facility.
<P>
<BR><b>[Macro]</b><BR>
<pre>
destructuring-bind <i>lambda-list</i> <i>expression</i> {<i>declaration</i>}* {<i>form</i>}*
</pre>
<P> This macro binds the variables specified in <i>lambda-list</i> to the corresponding
values in the tree structure resulting from evaluating the <i>expression</i>,
then executes the <i>form</i>s as an implicit <tt>progn</tt>.
<P>
A <tt>destructuring-bind</tt> <i>lambda-list</i> may contain
the lambda-list keywords <tt>&amp;optional</tt>, <tt>&amp;rest</tt>, <tt>&amp;key</tt>,
<tt>&amp;allow-other-keys</tt>, and <tt>&amp;aux</tt>; <tt>&amp;body</tt> and <tt>&amp;whole</tt>
may also be used as they are in <tt>defmacro</tt>, but <tt>&amp;environment</tt> may
<i>not</i> be used. Nested and dotted lambda-lists are also permitted
as for <tt>defmacro</tt>.
The idea is that a <tt>destructuring-bind</tt> <i>lambda-list</i>
has the same format as inner levels of a <tt>defmacro</tt> lambda-list.
<P>
If the result of evaluating the <i>expression</i> does not match the
destructuring pattern, an error should be signaled.
<br><img align=bottom alt="change_end" src="gif/change_end.gif">
<P>
<HR>
<P><ADDRESS>
AI.Repository@cs.cmu.edu
</ADDRESS>
</BODY>