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

59 lines
6.8 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 7.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="07_ac.htm">
<LINK REL=UP HREF="07_a.htm">
<LINK REL=NEXT HREF="07_ae.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="07_ac.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Previous]" SRC="../Graphics/Prev.gif" ALIGN=Bottom></A><A REL=UP HREF="07_a.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Up]" SRC="../Graphics/Up.gif" ALIGN=Bottom></A><A REL=NEXT HREF="07_ae.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Next]" SRC="../Graphics/Next.gif" ALIGN=Bottom></A></H1>
<HR>
<H2>
7.1.4 Rules for Initialization Arguments</H2> <P>
The <TT>:initarg</TT> slot option may be specified more than once for a given <A REL=DEFINITION HREF="26_glo_s.htm#slot"><I>slot</I></A>. <P>
The following rules specify when initialization arguments may be multiply defined: <P>
<P><DL><P>
<DT>* A given initialization argument can be used to initialize more than one <A REL=DEFINITION HREF="26_glo_s.htm#slot"><I>slot</I></A> if the same initialization argument name appears in more than one <TT>:initarg</TT> slot option. <P><DD>
<DT>* A given initialization argument name can appear in the <A REL=DEFINITION HREF="26_glo_l.htm#lambda_list"><I>lambda list</I></A> of more than one initialization <A REL=DEFINITION HREF="26_glo_m.htm#method"><I>method</I></A>. <P><DD>
<DT>* A given initialization argument name can appear both in an <TT>:initarg</TT> slot option and in the <A REL=DEFINITION HREF="26_glo_l.htm#lambda_list"><I>lambda list</I></A> of an initialization <A REL=DEFINITION HREF="26_glo_m.htm#method"><I>method</I></A>. <P><DD>
<P></DL><P>
<P>
If two or more initialization arguments that initialize the same <A REL=DEFINITION HREF="26_glo_s.htm#slot"><I>slot</I></A> are given in the arguments to <A REL=DEFINITION HREF="f_mk_ins.htm#make-instance"><B>make-instance</B></A>, the leftmost of these initialization arguments in the <A REL=DEFINITION HREF="26_glo_i.htm#initialization_argument_list"><I>initialization argument list</I></A> supplies the value, even if the initialization arguments have different names. <P>
If two or more different initialization arguments that initialize the same <A REL=DEFINITION HREF="26_glo_s.htm#slot"><I>slot</I></A> have default values and none is given explicitly in the arguments to <A REL=DEFINITION HREF="f_mk_ins.htm#make-instance"><B>make-instance</B></A>, the initialization argument that appears in a <TT>:default-initargs</TT> class option in the most specific of the <A REL=DEFINITION HREF="26_glo_c.htm#class"><I>classes</I></A> supplies the value. If a single <TT>:default-initargs</TT> class option specifies two or more initialization arguments that initialize the same <A REL=DEFINITION HREF="26_glo_s.htm#slot"><I>slot</I></A> and none is given explicitly in the arguments to <A REL=DEFINITION HREF="f_mk_ins.htm#make-instance"><B>make-instance</B></A>, the leftmost in the <TT>:default-initargs</TT> class option supplies the value, and the values of the remaining default value <A REL=DEFINITION HREF="26_glo_f.htm#form"><I>forms</I></A> are ignored. <P>
Initialization arguments given explicitly in the arguments to <A REL=DEFINITION HREF="f_mk_ins.htm#make-instance"><B>make-instance</B></A> appear to the left of defaulted initialization arguments. Suppose that the classes C1 and C2 supply the values of defaulted initialization arguments for different <A REL=DEFINITION HREF="26_glo_s.htm#slot"><I>slots</I></A>, and suppose that C1 is more specific than C2; then the defaulted initialization argument whose value is supplied by C1 is to the left of the defaulted initialization argument whose value is supplied by C2 in the <A REL=DEFINITION HREF="26_glo_d.htm#defaulted_initialization_argument_list"><I>defaulted initialization argument list</I></A>. If a single <TT>:default-initargs</TT> class option supplies the values of initialization arguments for two different <A REL=DEFINITION HREF="26_glo_s.htm#slot"><I>slots</I></A>, the initialization argument whose value is specified farther to the left in the <TT>:default-initargs</TT> class option appears farther to the left in the <A REL=DEFINITION HREF="26_glo_d.htm#defaulted_initialization_argument_list"><I>defaulted initialization argument list</I></A>. <P>
<P>
If a <A REL=DEFINITION HREF="26_glo_s.htm#slot"><I>slot</I></A> has both an <TT>:initform</TT> form and an <TT>:initarg</TT> slot option, and the initialization argument is defaulted using <TT>:default-initargs</TT> or is supplied to <A REL=DEFINITION HREF="f_mk_ins.htm#make-instance"><B>make-instance</B></A>, the captured <TT>:initform</TT> form is neither used nor evaluated. <P>
The following is an example of the above rules: <P>
<PRE>
(defclass q () ((x :initarg a)))
(defclass r (q) ((x :initarg b))
(:default-initargs a 1 b 2))
</PRE>
</TT> <P>
<P> <PRE>
Defaulted
Form Initialization Argument List Contents of Slot X
----------
(make-instance 'r) (a 1 b 2) 1
(make-instance 'r 'a 3) (a 3 b 2) 3
(make-instance 'r 'b 4) (b 4 a 1) 4
(make-instance 'r 'a 1 'a 2) (a 1 a 2 b 2) 1
</PRE>
<P> <P>
<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>