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

87 lines
4.9 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.6. Initialize-Instance</TITLE>
</HEAD>
<BODY>
<meta name="description" value=" Initialize-Instance">
<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=tex2html5383 HREF="node299.html"><IMG ALIGN=BOTTOM ALT="next" SRC="icons/next_motif.gif"></A> <A NAME=tex2html5381 HREF="node292.html"><IMG ALIGN=BOTTOM ALT="up" SRC="icons/up_motif.gif"></A> <A NAME=tex2html5375 HREF="node297.html"><IMG ALIGN=BOTTOM ALT="previous" SRC="icons/previous_motif.gif"></A> <A NAME=tex2html5385 HREF="node1.html"><IMG ALIGN=BOTTOM ALT="contents" SRC="icons/contents_motif.gif"></A> <A NAME=tex2html5386 HREF="index.html"><IMG ALIGN=BOTTOM ALT="index" SRC="icons/index_motif.gif"></A> <BR>
<B> Next:</B> <A NAME=tex2html5384 HREF="node299.html"> Definitions of Make-Instance </A>
<B>Up:</B> <A NAME=tex2html5382 HREF="node292.html"> Object Creation and </A>
<B> Previous:</B> <A NAME=tex2html5376 HREF="node297.html"> Shared-Initialize</A>
<HR> <P>
<H3><A NAME=SECTION003219600000000000000>28.1.9.6. Initialize-Instance</A></H3>
<P>
<img align=bottom alt="change_begin" src="gif/change_begin.gif"><br>
The generic function <tt>initialize-instance</tt> is called by
<tt>make-instance</tt> to initialize a newly created instance. It uses
standard method combination. Methods for
<tt>initialize-instance</tt> can be defined in order to perform any
initialization that cannot be achieved with the simple slot-filling
mechanisms.
<P>
<P>
During initialization, <tt>initialize-instance</tt> is invoked
after the following actions have been taken:
<P>
<UL><LI> The defaulted initialization argument list has been computed by
combining the supplied initialization argument list with any default
initialization arguments for the class.
<P>
<LI> The validity of the defaulted initialization argument
list has been checked. If any of the initialization arguments has not
been declared valid, an error is signaled.
<P>
<LI> A new instance whose slots are unbound has been created.
<P>
</UL>
<P>
The generic function <tt>initialize-instance</tt> is called with the
new instance and the defaulted initialization arguments. There is
a system-supplied primary method for <tt>initialize-instance</tt>
whose parameter specializer is the class <tt>standard-object</tt>. This
method calls the generic function <tt>shared-initialize</tt> to fill in
the slots according to the initialization arguments and the
<tt>:initform</tt> forms for the slots; the generic function
<tt>shared-initialize</tt> is called with the following arguments: the instance,
<tt>t</tt>, and the defaulted initialization arguments.
<P>
Note that <tt>initialize-instance</tt> provides the defaulted
initialization argument list in its call to <tt>shared-initialize</tt>,
so the first step performed by the system-supplied primary method for
<tt>shared-initialize</tt> takes into account both the initialization
arguments provided in the call to <tt>make-instance</tt> and the
defaulted initialization argument list.
<P>
Methods for <tt>initialize-instance</tt> can be defined to specify
actions to be taken when an instance is initialized. If only <tt>:after</tt>
methods for <tt>initialize-instance</tt> are defined, they will be
run after the system-supplied primary method for initialization and
therefore they will not interfere with the default behavior of
<tt>initialize-instance</tt>.
<P>
The Object System provides two functions that are useful in the bodies of
<tt>initialize-instance</tt> methods. The function <tt>slot-boundp</tt>
returns a boolean value that indicates whether a specified slot has a
value; this provides a mechanism for writing <tt>:after</tt> methods for
<tt>initialize-instance</tt> that initialize slots only if they have
not already been initialized. The function <tt>slot-makunbound</tt>
causes the slot to have no value.
<br><img align=bottom alt="change_end" src="gif/change_end.gif">
<P>
<BR> <HR><A NAME=tex2html5383 HREF="node299.html"><IMG ALIGN=BOTTOM ALT="next" SRC="icons/next_motif.gif"></A> <A NAME=tex2html5381 HREF="node292.html"><IMG ALIGN=BOTTOM ALT="up" SRC="icons/up_motif.gif"></A> <A NAME=tex2html5375 HREF="node297.html"><IMG ALIGN=BOTTOM ALT="previous" SRC="icons/previous_motif.gif"></A> <A NAME=tex2html5385 HREF="node1.html"><IMG ALIGN=BOTTOM ALT="contents" SRC="icons/contents_motif.gif"></A> <A NAME=tex2html5386 HREF="index.html"><IMG ALIGN=BOTTOM ALT="index" SRC="icons/index_motif.gif"></A> <BR>
<B> Next:</B> <A NAME=tex2html5384 HREF="node299.html"> Definitions of Make-Instance </A>
<B>Up:</B> <A NAME=tex2html5382 HREF="node292.html"> Object Creation and </A>
<B> Previous:</B> <A NAME=tex2html5376 HREF="node297.html"> Shared-Initialize</A>
<HR> <P>
<HR>
<P><ADDRESS>
AI.Repository@cs.cmu.edu
</ADDRESS>
</BODY>