1
0
Fork 0
cl-sites/HyperSpec-7-0/HyperSpec/Body/03_dad.htm
2024-04-01 10:24:07 +02:00

46 lines
8.5 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.1.4</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_dac.htm">
<LINK REL=UP HREF="03_da.htm">
<LINK REL=NEXT HREF="03_dada.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_dac.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Previous]" SRC="../Graphics/Prev.gif" ALIGN=Bottom></A><A REL=UP HREF="03_da.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Up]" SRC="../Graphics/Up.gif" ALIGN=Bottom></A><A REL=NEXT HREF="03_dada.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Next]" SRC="../Graphics/Next.gif" ALIGN=Bottom></A></H1>
<HR>
<H2>
3.4.1.4 Specifiers for keyword parameters</H2> <P>
If <TT>&amp;key</TT> is present, all specifiers up to the next <A REL=DEFINITION HREF="26_glo_l.htm#lambda_list_keyword"><I>lambda list keyword</I></A> or the end of the <A REL=DEFINITION HREF="26_glo_l.htm#list"><I>list</I></A> are keyword parameter specifiers. When keyword parameters are processed, the same arguments are processed that would be made into a <A REL=DEFINITION HREF="26_glo_l.htm#list"><I>list</I></A> for a <A REL=DEFINITION HREF="26_glo_r.htm#rest_parameter"><I>rest parameter</I></A>. It is permitted to specify both <TT>&amp;rest</TT> and <TT>&amp;key</TT>. In this case the remaining arguments are used for both purposes; that is, all remaining arguments are made into a <A REL=DEFINITION HREF="26_glo_l.htm#list"><I>list</I></A> for the <A REL=DEFINITION HREF="26_glo_r.htm#rest_parameter"><I>rest parameter</I></A>, and are also processed for the <TT>&amp;key</TT> parameters. If <TT>&amp;key</TT> is specified, there must remain an even number of arguments; see <A REL=CHILD HREF="03_eaf.htm">Section 3.5.1.6 (Odd Number of Keyword Arguments)</A>. These arguments are considered as pairs, the first argument in each pair being interpreted as a name and the second as the corresponding value. The first <A REL=DEFINITION HREF="26_glo_o.htm#object"><I>object</I></A> of each pair must be a <A REL=DEFINITION HREF="26_glo_s.htm#symbol"><I>symbol</I></A>; see <A REL=CHILD HREF="03_eae.htm">Section 3.5.1.5 (Invalid Keyword Arguments)</A>. The keyword parameter specifiers may optionally be followed by the <A REL=DEFINITION HREF="26_glo_l.htm#lambda_list_keyword"><I>lambda list keyword</I></A> <TT>&amp;allow-other-keys</TT>. <P>
In each keyword parameter specifier must be a name <I>var</I> for the parameter variable. If the <I>var</I> appears alone or in a <TT>(</TT><I>var</I><TT> </TT><I>init-form</I><TT>)</TT> combination, the keyword name used when matching <A REL=DEFINITION HREF="26_glo_a.htm#argument"><I>arguments</I></A> to <A REL=DEFINITION HREF="26_glo_p.htm#parameter"><I>parameters</I></A> is a <A REL=DEFINITION HREF="26_glo_s.htm#symbol"><I>symbol</I></A> in the <TT>KEYWORD</TT> package whose <A REL=DEFINITION HREF="26_glo_n.htm#name"><I>name</I></A> is the <A REL=DEFINITION HREF="26_glo_s.htm#same"><I>same</I></A> (under <A REL=DEFINITION HREF="f_stgeq_.htm#stringEQ"><B>string=</B></A>) as <I>var</I>'s. If the notation <TT>((</TT><I>keyword-name</I><TT> </TT><I>var</I><TT>) </TT><I>init-form</I><TT>)</TT> is used, then the keyword name used to match <A REL=DEFINITION HREF="26_glo_a.htm#argument"><I>arguments</I></A> to <A REL=DEFINITION HREF="26_glo_p.htm#parameter"><I>parameters</I></A> is <I>keyword-name</I>, which may be a <A REL=DEFINITION HREF="26_glo_s.htm#symbol"><I>symbol</I></A> in any <A REL=DEFINITION HREF="26_glo_p.htm#package"><I>package</I></A>. (Of course, if it is not a <A REL=DEFINITION HREF="26_glo_s.htm#symbol"><I>symbol</I></A> in the <TT>KEYWORD</TT> package, it does not necessarily self-evaluate, so care must be taken when calling the function to make sure that normal evaluation still yields the keyword name.) Thus <P>
<PRE>
(defun foo (&amp;key radix (type 'integer)) ...)
</PRE>
</TT> means exactly the same as <P>
<PRE>
(defun foo (&amp;key ((:radix radix)) ((:type type) 'integer)) ...)
</PRE>
</TT> <P>
The keyword parameter specifiers are, like all parameter specifiers, effectively processed from left to right. For each keyword parameter specifier, if there is an argument pair whose name matches that specifier's name (that is, the names are <A REL=DEFINITION HREF="f_eq.htm#eq"><B>eq</B></A>), then the parameter variable for that specifier is bound to the second item (the value) of that argument pair. If more than one such argument pair matches, the leftmost argument pair is used. If no such argument pair exists, then the <I>init-form</I> for that specifier is evaluated and the parameter variable is bound to that value (or to <A REL=DEFINITION HREF="a_nil.htm#nil"><B>nil</B></A> if no <I>init-form</I> was specified). <I>supplied-p-parameter</I> is treated as for <TT>&amp;optional</TT> parameters: it is bound to <A REL=DEFINITION HREF="26_glo_t.htm#true"><I>true</I></A> if there was a matching argument pair, and to <A REL=DEFINITION HREF="26_glo_f.htm#false"><I>false</I></A> otherwise. <P>
Unless keyword argument checking is suppressed, an argument pair must a name matched by a parameter specifier; see <A REL=CHILD HREF="03_ead.htm">Section 3.5.1.4 (Unrecognized Keyword Arguments)</A>. <P>
If keyword argument checking is suppressed, then it is permitted for an argument pair to match no parameter specifier, and the argument pair is ignored, but such an argument pair is accessible through the <A REL=DEFINITION HREF="26_glo_r.htm#rest_parameter"><I>rest parameter</I></A> if one was supplied. The purpose of these mechanisms is to allow sharing of argument lists among several <A REL=DEFINITION HREF="26_glo_l.htm#lambda_expression"><I>lambda expressions</I></A> and to allow either the caller or the called <A REL=DEFINITION HREF="26_glo_l.htm#lambda_expression"><I>lambda expression</I></A> to specify that such sharing may be taking place. <P>
Note that if <TT>&amp;key</TT> is present, a keyword argument of <TT>:allow-other-keys</TT> is always permitted---regardless of whether the associated value is <A REL=DEFINITION HREF="26_glo_t.htm#true"><I>true</I></A> or <A REL=DEFINITION HREF="26_glo_f.htm#false"><I>false</I></A>. However, if the value is <A REL=DEFINITION HREF="26_glo_f.htm#false"><I>false</I></A>, other non-matching keywords are not tolerated (unless <TT>&amp;allow-other-keys</TT> was used). <P>
Furthermore, if the receiving argument list specifies a regular argument which would be flagged by <TT>:allow-other-keys</TT>, then <TT>:allow-other-keys</TT> has both its special-cased meaning (identifying whether additional keywords are permitted) and its normal meaning (data flow into the function in question). <P>
<A REL=CHILD HREF="03_dada.htm"><H2>
3.4.1.4.1 Suppressing Keyword Argument Checking</H2></A><P><P><HR>The following <A REL=META HREF="../Front/X3J13Iss.htm">X3J13 cleanup issues</A>, <I>not part of the specification</I>, apply to this section:<P><UL><LI> <A REL=CHILD HREF="../Issues/iss008.htm">ALLOW-OTHER-KEYS-NIL:PERMIT</A><LI> <A REL=CHILD HREF="../Issues/iss208.htm">KEYWORD-ARGUMENT-NAME-PACKAGE:ANY</A><LI> <A REL=CHILD HREF="../Issues/iss010.htm">ARGUMENT-MISMATCH-ERROR-AGAIN:CONSISTENT</A><LI> <A REL=CHILD HREF="../Issues/iss269.htm">PLIST-DUPLICATES:ALLOW</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>