106 lines
6.1 KiB
HTML
106 lines
6.1 KiB
HTML
<!DOCTYPE HTML PUBLIC "-//W3O//DTD W3 HTML 2.0//EN">
|
|
<!Converted with LaTeX2HTML 0.6.5 (Tue Nov 15 1994) by Nikos Drakos (nikos@cbl.leeds.ac.uk), CBLU, University of Leeds >
|
|
<HEAD>
|
|
<TITLE>28.1.9.4. Rules for Initialization Arguments</TITLE>
|
|
</HEAD>
|
|
<BODY>
|
|
<meta name="description" value=" Rules for Initialization Arguments">
|
|
<meta name="keywords" value="clm">
|
|
<meta name="resource-type" value="document">
|
|
<meta name="distribution" value="global">
|
|
<P>
|
|
<b>Common Lisp the Language, 2nd Edition</b>
|
|
<BR> <HR><A NAME=tex2html5359 HREF="node297.html"><IMG ALIGN=BOTTOM ALT="next" SRC="icons/next_motif.gif"></A> <A NAME=tex2html5357 HREF="node292.html"><IMG ALIGN=BOTTOM ALT="up" SRC="icons/up_motif.gif"></A> <A NAME=tex2html5351 HREF="node295.html"><IMG ALIGN=BOTTOM ALT="previous" SRC="icons/previous_motif.gif"></A> <A NAME=tex2html5361 HREF="node1.html"><IMG ALIGN=BOTTOM ALT="contents" SRC="icons/contents_motif.gif"></A> <A NAME=tex2html5362 HREF="index.html"><IMG ALIGN=BOTTOM ALT="index" SRC="icons/index_motif.gif"></A> <BR>
|
|
<B> Next:</B> <A NAME=tex2html5360 HREF="node297.html"> Shared-Initialize</A>
|
|
<B>Up:</B> <A NAME=tex2html5358 HREF="node292.html"> Object Creation and </A>
|
|
<B> Previous:</B> <A NAME=tex2html5352 HREF="node295.html"> Defaulting of Initialization </A>
|
|
<HR> <P>
|
|
<H3><A NAME=SECTION003219400000000000000>28.1.9.4. Rules for Initialization Arguments</A></H3>
|
|
<P>
|
|
<img align=bottom alt="change_begin" src="gif/change_begin.gif"><br>
|
|
<A NAME=RulesforInitializationArgumentsSECTION>The</A>
|
|
<tt>:initarg</tt> slot option may be specified more than
|
|
once for a given slot.
|
|
The following rules specify when initialization arguments may be
|
|
multiply defined:
|
|
<P>
|
|
<UL><LI> A given initialization argument can be used to
|
|
initialize more than one slot if the same initialization argument name
|
|
appears in more than one <tt>:initarg</tt> slot option.
|
|
<P>
|
|
<LI> A given initialization argument name can appear
|
|
in the lambda-list of more than one initialization method.
|
|
<P>
|
|
<LI> A given initialization argument name can
|
|
appear both in an <tt>:initarg</tt> slot option and in the lambda-list
|
|
of an initialization method.
|
|
<P>
|
|
</UL>
|
|
<P>
|
|
If two or more initialization arguments that initialize
|
|
the same slot are given in the arguments to <tt>make-instance</tt>, the
|
|
leftmost of these initialization arguments in the initialization
|
|
argument list supplies the value, even if the initialization arguments
|
|
have different names.
|
|
<P>
|
|
If two or more different initialization arguments that
|
|
initialize the same slot have default values and none is given
|
|
explicitly in the arguments to <tt>make-instance</tt>, the initialization
|
|
argument that appears in a <tt>:default-initargs</tt> class option in the
|
|
most specific of the classes supplies the value. If a single
|
|
<tt>:default-initargs</tt> class option specifies two or more initialization
|
|
arguments that initialize the same slot and none is given explicitly
|
|
in the arguments to <tt>make-instance</tt>, the leftmost argument in the
|
|
<tt>:default-initargs</tt> class option supplies the value, and the values of
|
|
the remaining default value forms are ignored.
|
|
<P>
|
|
Initialization arguments given explicitly in the
|
|
arguments to <tt>make-instance</tt> appear to the left of defaulted
|
|
initialization arguments. Suppose that the classes <IMG ALIGN=BOTTOM ALT="" SRC="_24769_tex2html_wrap43387.gif"> and
|
|
<IMG ALIGN=BOTTOM ALT="" SRC="_24769_tex2html_wrap43591.gif"> supply the values of defaulted initialization arguments for
|
|
different slots, and suppose that <IMG ALIGN=BOTTOM ALT="" SRC="_24769_tex2html_wrap43387.gif"> is more specific than
|
|
<IMG ALIGN=BOTTOM ALT="" SRC="_24769_tex2html_wrap43591.gif">; then the defaulted initialization argument whose value is
|
|
supplied by <IMG ALIGN=BOTTOM ALT="" SRC="_24769_tex2html_wrap43387.gif"> is to the left of the defaulted initialization
|
|
argument whose value is supplied by <IMG ALIGN=BOTTOM ALT="" SRC="_24769_tex2html_wrap43591.gif"> in the defaulted
|
|
initialization argument list. If a single <tt>:default-initargs</tt>
|
|
class option supplies the values of initialization arguments for two
|
|
different slots, 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 defaulted initialization argument list.
|
|
<P>
|
|
If a slot 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 <tt>make-instance</tt>,
|
|
the captured <tt>:initform</tt> form is neither used nor evaluated.
|
|
<P>
|
|
The following is an example of the preceding rules:
|
|
<P>
|
|
<P><pre>
|
|
(defclass q () ((x :initarg a)))
|
|
|
|
(defclass r (q) ((x :initarg b))
|
|
(:default-initargs a 1 b 2))
|
|
</pre><P>
|
|
<P>
|
|
<listing>
|
|
Defaulted Initialization Contents
|
|
Form Argument List of Slot
|
|
=======================================================================
|
|
(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
|
|
=======================================================================
|
|
</listing>
|
|
<br><img align=bottom alt="change_end" src="gif/change_end.gif">
|
|
<P>
|
|
<BR> <HR><A NAME=tex2html5359 HREF="node297.html"><IMG ALIGN=BOTTOM ALT="next" SRC="icons/next_motif.gif"></A> <A NAME=tex2html5357 HREF="node292.html"><IMG ALIGN=BOTTOM ALT="up" SRC="icons/up_motif.gif"></A> <A NAME=tex2html5351 HREF="node295.html"><IMG ALIGN=BOTTOM ALT="previous" SRC="icons/previous_motif.gif"></A> <A NAME=tex2html5361 HREF="node1.html"><IMG ALIGN=BOTTOM ALT="contents" SRC="icons/contents_motif.gif"></A> <A NAME=tex2html5362 HREF="index.html"><IMG ALIGN=BOTTOM ALT="index" SRC="icons/index_motif.gif"></A> <BR>
|
|
<B> Next:</B> <A NAME=tex2html5360 HREF="node297.html"> Shared-Initialize</A>
|
|
<B>Up:</B> <A NAME=tex2html5358 HREF="node292.html"> Object Creation and </A>
|
|
<B> Previous:</B> <A NAME=tex2html5352 HREF="node295.html"> Defaulting of Initialization </A>
|
|
<HR> <P>
|
|
<HR>
|
|
<P><ADDRESS>
|
|
AI.Repository@cs.cmu.edu
|
|
</ADDRESS>
|
|
</BODY>
|