71 lines
8.2 KiB
HTML
71 lines
8.2 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.6</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_de.htm">
|
|
<LINK REL=UP HREF="03_d.htm">
|
|
<LINK REL=NEXT HREF="03_dg.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_de.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Previous]" SRC="../Graphics/Prev.gif" ALIGN=Bottom></A><A REL=UP HREF="03_d.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Up]" SRC="../Graphics/Up.gif" ALIGN=Bottom></A><A REL=NEXT HREF="03_dg.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Next]" SRC="../Graphics/Next.gif" ALIGN=Bottom></A></H1>
|
|
|
|
<HR>
|
|
|
|
<H2>
|
|
3.4.6 Boa Lambda Lists</H2> <P>
|
|
A <A REL=DEFINITION HREF="26_glo_b.htm#boa_lambda_list"><I>boa lambda list</I></A> is a <A REL=DEFINITION HREF="26_glo_l.htm#lambda_list"><I>lambda list</I></A> that is syntactically like an <A REL=DEFINITION HREF="26_glo_o.htm#ordinary_lambda_list"><I>ordinary lambda list</I></A>, but that is processed in ``<B>b</B>y <B>o</B>rder of <B>a</B>rgument'' style. <P>
|
|
A <A REL=DEFINITION HREF="26_glo_b.htm#boa_lambda_list"><I>boa lambda list</I></A> is used only in a <A REL=DEFINITION HREF="m_defstr.htm#defstruct"><B>defstruct</B></A> <A REL=DEFINITION HREF="26_glo_f.htm#form"><I>form</I></A>, when explicitly specifying the <A REL=DEFINITION HREF="26_glo_l.htm#lambda_list"><I>lambda list</I></A> of a constructor <A REL=DEFINITION HREF="26_glo_f.htm#function"><I>function</I></A> (sometimes called a ``boa constructor''). <P>
|
|
The <TT>&optional</TT>, <TT>&rest</TT>, <TT>&aux</TT>, <TT>&key</TT>, and <TT>&allow-other-keys</TT> <A REL=DEFINITION HREF="26_glo_l.htm#lambda_list_keyword"><I>lambda list keywords</I></A> are recognized in a <A REL=DEFINITION HREF="26_glo_b.htm#boa_lambda_list"><I>boa lambda list</I></A>. The way these <A REL=DEFINITION HREF="26_glo_l.htm#lambda_list_keyword"><I>lambda list keywords</I></A> differ from their use in an <A REL=DEFINITION HREF="26_glo_o.htm#ordinary_lambda_list"><I>ordinary lambda list</I></A> follows. <P>
|
|
Consider this example, which describes how <B>destruct</B> processes its <TT>:constructor</TT> option. <P>
|
|
<PRE>
|
|
(:constructor create-foo
|
|
(a &optional b (c 'sea) &rest d &aux e (f 'eff)))
|
|
</PRE>
|
|
</TT> <P>
|
|
This defines <TT>create-foo</TT> to be a constructor of one or more arguments. The first argument is used to initialize the <TT>a</TT> slot. The second argument is used to initialize the <TT>b</TT> slot. If there isn't any second argument, then the default value given in the body of the <A REL=DEFINITION HREF="m_defstr.htm#defstruct"><B>defstruct</B></A> (if given) is used instead. The third argument is used to initialize the <TT>c</TT> slot. If there isn't any third argument, then the symbol <TT>sea</TT> is used instead. Any arguments following the third argument are collected into a <A REL=DEFINITION HREF="26_glo_l.htm#list"><I>list</I></A> and used to initialize the <TT>d</TT> slot. If there are three or fewer arguments, then <A REL=DEFINITION HREF="a_nil.htm#nil"><B>nil</B></A> is placed in the <TT>d</TT> slot. The <TT>e</TT> slot is not initialized; its initial value is <A REL=DEFINITION HREF="26_glo_i.htm#implementation-defined"><I>implementation-defined</I></A>. Finally, the <TT>f</TT> slot is initialized to contain the symbol <TT>eff</TT>. <TT>&key</TT> and <TT>&allow-other-keys</TT> arguments default in a manner similar to that of <TT>&optional</TT> arguments: if no default is supplied in the <A REL=DEFINITION HREF="26_glo_l.htm#lambda_list"><I>lambda list</I></A> then the default value given in the body of the <A REL=DEFINITION HREF="m_defstr.htm#defstruct"><B>defstruct</B></A> (if given) is used instead. For example: <P>
|
|
<PRE>
|
|
(defstruct (foo (:constructor CREATE-FOO (a &optional b (c 'sea)
|
|
&key (d 2)
|
|
&aux e (f 'eff))))
|
|
(a 1) (b 2) (c 3) (d 4) (e 5) (f 6))
|
|
|
|
(create-foo 10) => #S(FOO A 10 B 2 C SEA D 2 E implemention-dependent F EFF)
|
|
(create-foo 10 'bee 'see :d 'dee)
|
|
=> #S(FOO A 10 B BEE C SEE D DEE E implemention-dependent F EFF)
|
|
</PRE>
|
|
</TT> <P>
|
|
If keyword arguments of the form <TT>((</TT><I>key</I><TT> </TT><I>var</I><TT>) </TT>[<TT></TT><I>default</I><TT> </TT>[<TT></TT><I>svar</I><TT></TT>]<TT></TT>]<TT>)</TT> are specified, the <A REL=DEFINITION HREF="26_glo_s.htm#slot"><I>slot</I></A> <A REL=DEFINITION HREF="26_glo_n.htm#name"><I>name</I></A> is matched with <I>var</I> (not <I>key</I>). <P>
|
|
The actions taken in the <TT>b</TT> and <TT>e</TT> cases were carefully chosen to allow the user to specify all possible behaviors. The <TT>&aux</TT> variables can be used to completely override the default initializations given in the body. <P>
|
|
If no default value is supplied for an <A REL=DEFINITION HREF="26_glo_a.htm#aux_variable"><I>aux variable</I></A> variable, the consequences are undefined if an attempt is later made to read the corresponding <A REL=DEFINITION HREF="26_glo_s.htm#slot"><I>slot</I></A>'s value before a value is explicitly assigned. If such a <A REL=DEFINITION HREF="26_glo_s.htm#slot"><I>slot</I></A> has a <TT>:type</TT> option specified, this suppressed initialization does not imply a type mismatch situation; the declared type is only required to apply when the <A REL=DEFINITION HREF="26_glo_s.htm#slot"><I>slot</I></A> is finally assigned. <P>
|
|
With this definition, the following can be written: <P>
|
|
<PRE>
|
|
(create-foo 1 2)
|
|
</PRE>
|
|
</TT> instead of <P>
|
|
<PRE>
|
|
(make-foo :a 1 :b 2)
|
|
</PRE>
|
|
</TT> and <TT>create-foo</TT> provides defaulting different from that of <TT>make-foo</TT>. <P>
|
|
Additional arguments that do not correspond to slot names but are merely present to supply values used in subsequent initialization computations are allowed. For example, in the definition <P>
|
|
<PRE>
|
|
(defstruct (frob (:constructor create-frob
|
|
(a &key (b 3 have-b) (c-token 'c)
|
|
(c (list c-token (if have-b 7 2))))))
|
|
a b c)
|
|
</PRE>
|
|
</TT> <P>
|
|
the <TT>c-token</TT> argument is used merely to supply a value used in the initialization of the <TT>c</TT> slot. The <A REL=DEFINITION HREF="26_glo_s.htm#supplied-p_parameter"><I>supplied-p parameters</I></A> associated with <A REL=DEFINITION HREF="26_glo_o.htm#optional_parameter"><I>optional parameters</I></A> and <A REL=DEFINITION HREF="26_glo_k.htm#keyword_parameter"><I>keyword parameters</I></A> might also be used this way. <P>
|
|
<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/iss019.htm">BOA-AUX-INITIALIZATION:ERROR-ON-READ</A><LI> <A REL=CHILD HREF="../Issues/iss109.htm">DEFSTRUCT-CONSTRUCTOR-KEY-MIXTURE:ALLOW-KEY</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>
|