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

34 lines
7 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.3</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_ab.htm">
<LINK REL=UP HREF="07_a.htm">
<LINK REL=NEXT HREF="07_ad.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_ab.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_ad.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Next]" SRC="../Graphics/Next.gif" ALIGN=Bottom></A></H1>
<HR>
<H2>
7.1.3 Defaulting of Initialization Arguments</H2> <P>
A default value <A REL=DEFINITION HREF="26_glo_f.htm#form"><I>form</I></A> can be supplied for an initialization argument by using the <TT>:default-initargs</TT> <A REL=DEFINITION HREF="26_glo_c.htm#class"><I>class</I></A> option. If an initialization argument is declared valid by some particular <A REL=DEFINITION HREF="26_glo_c.htm#class"><I>class</I></A>, its default value form might be specified by a different <A REL=DEFINITION HREF="26_glo_c.htm#class"><I>class</I></A>. In this case <TT>:default-initargs</TT> is used to supply a default value for an inherited initialization argument. <P>
The <TT>:default-initargs</TT> option is used only to provide default values for initialization arguments; it does not declare a <A REL=DEFINITION HREF="26_glo_s.htm#symbol"><I>symbol</I></A> as a valid initialization argument name. Furthermore, the <TT>:default-initargs</TT> option is used only to provide default values for initialization arguments when making an <A REL=DEFINITION HREF="26_glo_i.htm#instance"><I>instance</I></A>. <P>
The argument to the <TT>:default-initargs</TT> class option is a list of alternating initialization argument names and <A REL=DEFINITION HREF="26_glo_f.htm#form"><I>forms</I></A>. Each <A REL=DEFINITION HREF="26_glo_f.htm#form"><I>form</I></A> is the default value form for the corresponding initialization argument. The default value <A REL=DEFINITION HREF="26_glo_f.htm#form"><I>form</I></A> of an initialization argument is used and evaluated only if that initialization argument does not appear in the arguments to <A REL=DEFINITION HREF="f_mk_ins.htm#make-instance"><B>make-instance</B></A> and is not defaulted by a more specific <A REL=DEFINITION HREF="26_glo_c.htm#class"><I>class</I></A>. The default value <A REL=DEFINITION HREF="26_glo_f.htm#form"><I>form</I></A> is evaluated in the lexical environment of the <A REL=DEFINITION HREF="m_defcla.htm#defclass"><B>defclass</B></A> form that supplied it; the resulting value is used as the initialization argument's value. <P>
The initialization arguments supplied to <A REL=DEFINITION HREF="f_mk_ins.htm#make-instance"><B>make-instance</B></A> are combined with defaulted initialization arguments to produce a <A REL=DEFINITION HREF="26_glo_d.htm#defaulted_initialization_argument_list"><I>defaulted initialization argument list</I></A>. A <A REL=DEFINITION HREF="26_glo_d.htm#defaulted_initialization_argument_list"><I>defaulted initialization argument list</I></A> is a list of alternating initialization argument names and values in which unsupplied initialization arguments are defaulted and in which the explicitly supplied initialization arguments appear earlier in the list than the defaulted initialization arguments. Defaulted initialization arguments are ordered according to the order in the <A REL=DEFINITION HREF="26_glo_c.htm#class_precedence_list"><I>class precedence list</I></A> of the <A REL=DEFINITION HREF="26_glo_c.htm#class"><I>classes</I></A> that supplied the default values. <P>
There is a distinction between the purposes of the <TT>:default-initargs</TT> and the <TT>:initform</TT> options with respect to the initialization of <A REL=DEFINITION HREF="26_glo_s.htm#slot"><I>slots</I></A>. The <TT>:default-initargs</TT> class option provides a mechanism for the user to give a default value <A REL=DEFINITION HREF="26_glo_f.htm#form"><I>form</I></A> for an initialization argument without knowing whether the initialization argument initializes a <A REL=DEFINITION HREF="26_glo_s.htm#slot"><I>slot</I></A> or is passed to a <A REL=DEFINITION HREF="26_glo_m.htm#method"><I>method</I></A>. If that initialization argument is not explicitly supplied in a call to <A REL=DEFINITION HREF="f_mk_ins.htm#make-instance"><B>make-instance</B></A>, the default value <A REL=DEFINITION HREF="26_glo_f.htm#form"><I>form</I></A> is used, just as if it had been supplied in the call. In contrast, the <TT>:initform</TT> slot option provides a mechanism for the user to give a default initial value form for a <A REL=DEFINITION HREF="26_glo_s.htm#slot"><I>slot</I></A>. An <TT>:initform</TT> form is used to initialize a <A REL=DEFINITION HREF="26_glo_s.htm#slot"><I>slot</I></A> only if no initialization argument associated with that <A REL=DEFINITION HREF="26_glo_s.htm#slot"><I>slot</I></A> is given as an argument to <A REL=DEFINITION HREF="f_mk_ins.htm#make-instance"><B>make-instance</B></A> or is defaulted by <TT>:default-initargs</TT>. <P>
The order of evaluation of default value <A REL=DEFINITION HREF="26_glo_f.htm#form"><I>forms</I></A> for initialization arguments and the order of evaluation of <TT>:initform</TT> forms are undefined. If the order of evaluation is important, <A REL=DEFINITION HREF="f_init_i.htm#initialize-instance"><B>initialize-instance</B></A> or <A REL=DEFINITION HREF="f_shared.htm#shared-initialize"><B>shared-initialize</B></A> <A REL=DEFINITION HREF="26_glo_m.htm#method"><I>methods</I></A> should be used instead. <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>