49 lines
6.1 KiB
HTML
49 lines
6.1 KiB
HTML
<!-- Common Lisp HyperSpec (TM), version 7.0 generated by Kent M. Pitman on Mon, 11-Apr-2005 2:31am EDT -->
|
|
<HTML>
|
|
<HEAD>
|
|
<TITLE>CLHS: Section 3.4.4.1.2</TITLE>
|
|
<LINK HREF="../Data/clhs.css" REL="stylesheet" TYPE="text/css" />
|
|
<META HTTP-EQUIV="Author" CONTENT="Kent M. Pitman">
|
|
<META HTTP-EQUIV="Organization" CONTENT="LispWorks Ltd.">
|
|
<LINK REL=TOP HREF="../Front/index.htm">
|
|
<LINK REL=COPYRIGHT HREF="../Front/Help.htm#Legal">
|
|
<LINK REL=DISCLAIMER HREF="../Front/Help.htm#Disclaimer">
|
|
<LINK REL=PREV HREF="03_ddaaa.htm">
|
|
<LINK REL=UP HREF="03_dda.htm">
|
|
<LINK REL=NEXT HREF="03_de.htm">
|
|
</HEAD>
|
|
<BODY>
|
|
<H1><A REV=MADE HREF="http://www.lispworks.com/"><IMG WIDTH=80 HEIGHT=65 ALT="[LISPWORKS]" SRC="../Graphics/LWSmall.gif" ALIGN=Bottom></A><A REL=TOP HREF="../Front/index.htm"><IMG WIDTH=237 HEIGHT=65 ALT="[Common Lisp HyperSpec (TM)]" SRC="../Graphics/CLHS_Sm.gif" ALIGN=Bottom></A> <A REL=PREV HREF="03_ddaaa.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Previous]" SRC="../Graphics/Prev.gif" ALIGN=Bottom></A><A REL=UP HREF="03_dda.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Up]" SRC="../Graphics/Up.gif" ALIGN=Bottom></A><A REL=NEXT HREF="03_de.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Next]" SRC="../Graphics/Next.gif" ALIGN=Bottom></A></H1>
|
|
|
|
<HR>
|
|
|
|
<H2>
|
|
3.4.4.1.2 Lambda-list-directed Destructuring by Lambda Lists</H2> <P>
|
|
An extension of data-directed destructuring of <A REL=DEFINITION HREF="26_glo_t.htm#tree"><I>trees</I></A> is lambda-list-directed destructuring. This derives from the analogy between the three-element destructuring pattern <P>
|
|
<TT>(first second third)</TT> <P>
|
|
and the three-argument <A REL=DEFINITION HREF="26_glo_l.htm#lambda_list"><I>lambda list</I></A> <P>
|
|
<TT>(first second third)</TT> <P>
|
|
Lambda-list-directed destructuring is identical to data-directed destructuring if no <A REL=DEFINITION HREF="26_glo_l.htm#lambda_list_keyword"><I>lambda list keywords</I></A> appear in the pattern. Any list in the pattern (whether a sub-list or the whole pattern itself) that contains a <A REL=DEFINITION HREF="26_glo_l.htm#lambda_list_keyword"><I>lambda list keyword</I></A> is interpreted specially. Elements of the list to the left of the first <A REL=DEFINITION HREF="26_glo_l.htm#lambda_list_keyword"><I>lambda list keyword</I></A> are treated as destructuring patterns, as usual, but the remaining elements of the list are treated like a function's <A REL=DEFINITION HREF="26_glo_l.htm#lambda_list"><I>lambda list</I></A> except that where a variable would normally be required, an arbitrary destructuring pattern is allowed. Note that in case of ambiguity, <A REL=DEFINITION HREF="26_glo_l.htm#lambda_list"><I>lambda list</I></A> syntax is preferred over destructuring syntax. Thus, after <TT>&optional</TT> a list of elements is a list of a destructuring pattern and a default value form. <P>
|
|
The detailed behavior of each <A REL=DEFINITION HREF="26_glo_l.htm#lambda_list_keyword"><I>lambda list keyword</I></A> in a lambda-list-directed destructuring pattern is as follows: <P>
|
|
<P><DL><DT><TT>&optional</TT> <P><DD>
|
|
Each following element is a variable or a list of a destructuring pattern, a default value form, and a supplied-p variable. The default value and the supplied-p variable can be omitted. If the list being destructured ends early, so that it does not have an element to match against this destructuring (sub)-pattern, the default form is evaluated and destructured instead. The supplied-p variable receives the value <A REL=DEFINITION HREF="a_nil.htm#nil"><B>nil</B></A> if the default form is used, <A REL=DEFINITION HREF="a_t.htm#t"><B>t</B></A> otherwise. <P>
|
|
<DT><TT>&rest</TT>, <TT>&body</TT> <P><DD>
|
|
The next element is a destructuring pattern that matches the rest of the list. <TT>&body</TT> is identical to <TT>&rest</TT> but declares that what is being matched is a list of forms that constitutes the body of <A REL=DEFINITION HREF="26_glo_f.htm#form"><I>form</I></A>. This next element must be the last unless a <A REL=DEFINITION HREF="26_glo_l.htm#lambda_list_keyword"><I>lambda list keyword</I></A> follows it. <P>
|
|
<DT><TT>&aux</TT> <P><DD>
|
|
The remaining elements are not destructuring patterns at all, but are auxiliary variable bindings. <P>
|
|
<DT><TT>&whole</TT> <P><DD>
|
|
The next element is a destructuring pattern that matches the entire form in a macro, or the entire <A REL=DEFINITION HREF="26_glo_s.htm#subexpression"><I>subexpression</I></A> at inner levels. <P>
|
|
<DT><TT>&key</TT> <P><DD>
|
|
Each following element is one of <P><DL><P>
|
|
<DT> a <A REL=DEFINITION HREF="26_glo_v.htm#variable"><I>variable</I></A>, <P><DD>
|
|
<DT>or a list of a variable, an optional initialization form, and an optional supplied-p variable. <P><DD>
|
|
<DT>or a list of a list of a keyword and a destructuring pattern, an optional initialization form, and an optional supplied-p variable. <P><DD></DL>The rest of the list being destructured is taken to be alternating keywords and values and is taken apart appropriately. <P>
|
|
<DT><TT>&allow-other-keys</TT> <P><DD>
|
|
Stands by itself. <P></DL><P>
|
|
<P><HR>The following <A REL=META HREF="../Front/X3J13Iss.htm">X3J13 cleanup issue</A>, <I>not part of the specification</I>, applies to this section:<P><UL><LI> <A REL=CHILD HREF="../Issues/iss106.htm">DEFMACRO-LAMBDA-LIST:TIGHTEN-DESCRIPTION</A><P></UL><HR>
|
|
|
|
<A REL=NAVIGATOR HREF="../Front/StartPts.htm"><IMG WIDTH=80 HEIGHT=40 ALT="[Starting Points]" SRC="../Graphics/StartPts.gif" ALIGN=Bottom></A><A REL=TOC HREF="../Front/Contents.htm"><IMG WIDTH=80 HEIGHT=40 ALT="[Contents]" SRC="../Graphics/Contents.gif" ALIGN=Bottom></A><A REL=INDEX HREF="../Front/X_Master.htm"><IMG WIDTH=80 HEIGHT=40 ALT="[Index]" SRC="../Graphics/Index.gif" ALIGN=Bottom></A><A REL=INDEX HREF="../Front/X_Symbol.htm"><IMG WIDTH=80 HEIGHT=40 ALT="[Symbols]" SRC="../Graphics/Symbols.gif" ALIGN=Bottom></A><A REL=GLOSSARY HREF="../Body/26_a.htm"><IMG WIDTH=80 HEIGHT=40 ALT="[Glossary]" SRC="../Graphics/Glossary.gif" ALIGN=Bottom></A><A HREF="../Front/X3J13Iss.htm"><IMG WIDTH=80 HEIGHT=40 ALT="[Issues]" SRC="../Graphics/Issues.gif" ALIGN=Bottom></A><BR>
|
|
|
|
<A REL=COPYRIGHT HREF="../Front/Help.htm#Legal"><I>Copyright 1996-2005, LispWorks Ltd. All rights reserved.</I></A><P>
|
|
</BODY>
|
|
</HTML>
|