1
0
Fork 0
cl-sites/www.cs.cmu.edu/Groups/AI/html/cltl/clm/node297.html
2023-10-25 11:23:21 +02:00

91 lines
5 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.5. Shared-Initialize</TITLE>
</HEAD>
<BODY>
<meta name="description" value=" Shared-Initialize">
<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=tex2html5371 HREF="node298.html"><IMG ALIGN=BOTTOM ALT="next" SRC="icons/next_motif.gif"></A> <A NAME=tex2html5369 HREF="node292.html"><IMG ALIGN=BOTTOM ALT="up" SRC="icons/up_motif.gif"></A> <A NAME=tex2html5363 HREF="node296.html"><IMG ALIGN=BOTTOM ALT="previous" SRC="icons/previous_motif.gif"></A> <A NAME=tex2html5373 HREF="node1.html"><IMG ALIGN=BOTTOM ALT="contents" SRC="icons/contents_motif.gif"></A> <A NAME=tex2html5374 HREF="index.html"><IMG ALIGN=BOTTOM ALT="index" SRC="icons/index_motif.gif"></A> <BR>
<B> Next:</B> <A NAME=tex2html5372 HREF="node298.html"> Initialize-Instance</A>
<B>Up:</B> <A NAME=tex2html5370 HREF="node292.html"> Object Creation and </A>
<B> Previous:</B> <A NAME=tex2html5364 HREF="node296.html"> Rules for Initialization </A>
<HR> <P>
<H3><A NAME=SECTION003219500000000000000>28.1.9.5. Shared-Initialize</A></H3>
<P>
<img align=bottom alt="change_begin" src="gif/change_begin.gif"><br>
<A NAME=SharedInitializeSECTION>The</A>
generic function <tt>shared-initialize</tt> is used to fill the slots
of an instance using initialization arguments and <tt>:initform</tt>
forms when an instance is created, when an instance is re-initialized,
when an instance is updated to conform to a redefined class, and when
an instance is updated to conform to a different class. It uses
standard method combination. It takes the following arguments: the
instance to be initialized, a specification of a set of names of slots
accessible in that instance, and any number of initialization
arguments. The arguments after the first two must form an initialization
argument list.
<P>
The second argument to <tt>shared-initialize</tt> may be one of the following:
<P>
<UL><LI> It can be a list of slot names, which specifies
the set of those slot names.
<P>
<LI> It can be <tt>nil</tt>, which specifies the empty set of
slot names.
<P>
<LI> It can be the symbol <tt>t</tt>, which specifies the set of
all of the slots.
<P>
</UL>
<P>
There is a system-supplied primary method for
<tt>shared-initialize</tt> whose first parameter specializer is the class
<tt>standard-object</tt>. This method behaves as follows on each slot,
whether shared or local:
<P>
<UL><LI> If an initialization argument in the initialization
argument list specifies a value for that slot, that value is stored
into the slot, even if a value has already been stored in the slot
before the method is run. The affected slots are independent of which
slots are indicated by the second argument to <tt>shared-initialize</tt>.
<P>
<LI> Any slots indicated by the second argument that are still
unbound at this point are initialized according to their
<tt>:initform</tt> forms. For any such slot that has an <tt>:initform</tt> form,
that form is evaluated in the lexical environment of its defining
<tt>defclass</tt> form and the result is stored into the slot. For example,
if a <tt>:before</tt> method stores a value in the slot, the
<tt>:initform</tt> form will not be used to supply a value for the slot. If
the second argument specifies a name that does not correspond to any
slots accessible in the instance, the results are unspecified.
<P>
<LI> The rules mentioned in section <A HREF="node296.html#RulesforInitializationArgumentsSECTION">28.1.9.4</A> are obeyed.
<P>
</UL>
<P>
The generic function <tt>shared-initialize</tt> is called by the
system-supplied primary methods for the generic functions
<tt>initialize-instance</tt>,
<tt>reinitialize-instance</tt>,
<tt>update-instance-for-different-class</tt>, and
<tt>update-instance-for-redefined-class</tt>.
Thus methods can be written for
<tt>shared-initialize</tt> to specify actions that should be taken in all of
these contexts.
<br><img align=bottom alt="change_end" src="gif/change_end.gif">
<P>
<BR> <HR><A NAME=tex2html5371 HREF="node298.html"><IMG ALIGN=BOTTOM ALT="next" SRC="icons/next_motif.gif"></A> <A NAME=tex2html5369 HREF="node292.html"><IMG ALIGN=BOTTOM ALT="up" SRC="icons/up_motif.gif"></A> <A NAME=tex2html5363 HREF="node296.html"><IMG ALIGN=BOTTOM ALT="previous" SRC="icons/previous_motif.gif"></A> <A NAME=tex2html5373 HREF="node1.html"><IMG ALIGN=BOTTOM ALT="contents" SRC="icons/contents_motif.gif"></A> <A NAME=tex2html5374 HREF="index.html"><IMG ALIGN=BOTTOM ALT="index" SRC="icons/index_motif.gif"></A> <BR>
<B> Next:</B> <A NAME=tex2html5372 HREF="node298.html"> Initialize-Instance</A>
<B>Up:</B> <A NAME=tex2html5370 HREF="node292.html"> Object Creation and </A>
<B> Previous:</B> <A NAME=tex2html5364 HREF="node296.html"> Rules for Initialization </A>
<HR> <P>
<HR>
<P><ADDRESS>
AI.Repository@cs.cmu.edu
</ADDRESS>
</BODY>