44 lines
13 KiB
HTML
44 lines
13 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.5.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_eb.htm">
|
||
|
<LINK REL=UP HREF="07_e.htm">
|
||
|
<LINK REL=NEXT HREF="07_f.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_eb.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Previous]" SRC="../Graphics/Prev.gif" ALIGN=Bottom></A><A REL=UP HREF="07_e.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Up]" SRC="../Graphics/Up.gif" ALIGN=Bottom></A><A REL=NEXT HREF="07_f.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Next]" SRC="../Graphics/Next.gif" ALIGN=Bottom></A></H1>
|
||
|
|
||
|
<HR>
|
||
|
|
||
|
<H2>
|
||
|
7.5.3 Inheritance of Slots and Slot Options</H2> <P>
|
||
|
The set of the <A REL=DEFINITION HREF="26_glo_n.htm#name"><I>names</I></A> of all <A REL=DEFINITION HREF="26_glo_s.htm#slot"><I>slots</I></A> <A REL=DEFINITION HREF="26_glo_a.htm#accessible"><I>accessible</I></A> in an <A REL=DEFINITION HREF="26_glo_i.htm#instance"><I>instance</I></A> of a <A REL=DEFINITION HREF="26_glo_c.htm#class"><I>class</I></A> C is the union of the sets of <A REL=DEFINITION HREF="26_glo_n.htm#name"><I>names</I></A> of <A REL=DEFINITION HREF="26_glo_s.htm#slot"><I>slots</I></A> defined by C and its <A REL=DEFINITION HREF="26_glo_s.htm#superclass"><I>superclasses</I></A>. The structure of an <A REL=DEFINITION HREF="26_glo_i.htm#instance"><I>instance</I></A> is the set of <A REL=DEFINITION HREF="26_glo_n.htm#name"><I>names</I></A> of <A REL=DEFINITION HREF="26_glo_l.htm#local_slot"><I>local slots</I></A> in that <A REL=DEFINITION HREF="26_glo_i.htm#instance"><I>instance</I></A>. <P>
|
||
|
In the simplest case, only one <A REL=DEFINITION HREF="26_glo_c.htm#class"><I>class</I></A> among C and its <A REL=DEFINITION HREF="26_glo_s.htm#superclass"><I>superclasses</I></A> defines a <A REL=DEFINITION HREF="26_glo_s.htm#slot"><I>slot</I></A> with a given <A REL=DEFINITION HREF="26_glo_s.htm#slot"><I>slot</I></A> name. If a <A REL=DEFINITION HREF="26_glo_s.htm#slot"><I>slot</I></A> is defined by a <A REL=DEFINITION HREF="26_glo_s.htm#superclass"><I>superclass</I></A> of C, the <A REL=DEFINITION HREF="26_glo_s.htm#slot"><I>slot</I></A> is said to be inherited. The characteristics of the <A REL=DEFINITION HREF="26_glo_s.htm#slot"><I>slot</I></A> are determined by the <A REL=DEFINITION HREF="26_glo_s.htm#slot_specifier"><I>slot specifier</I></A> of the defining <A REL=DEFINITION HREF="26_glo_c.htm#class"><I>class</I></A>. Consider the defining <A REL=DEFINITION HREF="26_glo_c.htm#class"><I>class</I></A> for a slot S. If the value of the <TT>:allocation</TT> slot option is <TT>:instance</TT>, then S is a <A REL=DEFINITION HREF="26_glo_l.htm#local_slot"><I>local slot</I></A> and each <A REL=DEFINITION HREF="26_glo_i.htm#instance"><I>instance</I></A> of C has its own <A REL=DEFINITION HREF="26_glo_s.htm#slot"><I>slot</I></A> named S that stores its own value. If the value of the <TT>:allocation</TT> slot option is <TT>:class</TT>, then S is a <A REL=DEFINITION HREF="26_glo_s.htm#shared_slot"><I>shared slot</I></A>, the <A REL=DEFINITION HREF="26_glo_c.htm#class"><I>class</I></A> that defined S stores the value, and all <A REL=DEFINITION HREF="26_glo_i.htm#instance"><I>instances</I></A> of C can <A REL=DEFINITION HREF="26_glo_a.htm#access"><I>access</I></A> that single <A REL=DEFINITION HREF="26_glo_s.htm#slot"><I>slot</I></A>. If the <TT>:allocation</TT> slot option is omitted, <TT>:instance</TT> is used. <P>
|
||
|
In general, more than one <A REL=DEFINITION HREF="26_glo_c.htm#class"><I>class</I></A> among C and its <A REL=DEFINITION HREF="26_glo_s.htm#superclass"><I>superclasses</I></A> can define a <A REL=DEFINITION HREF="26_glo_s.htm#slot"><I>slot</I></A> with a given <A REL=DEFINITION HREF="26_glo_n.htm#name"><I>name</I></A>. In such cases, only one <A REL=DEFINITION HREF="26_glo_s.htm#slot"><I>slot</I></A> with the given name is <A REL=DEFINITION HREF="26_glo_a.htm#accessible"><I>accessible</I></A> in an <A REL=DEFINITION HREF="26_glo_i.htm#instance"><I>instance</I></A> of C, and the characteristics of that <A REL=DEFINITION HREF="26_glo_s.htm#slot"><I>slot</I></A> are a combination of the several <A REL=DEFINITION HREF="26_glo_s.htm#slot"><I>slot</I></A> specifiers, computed as follows: <P>
|
||
|
<P><DL><P>
|
||
|
<DT>* All the <A REL=DEFINITION HREF="26_glo_s.htm#slot_specifier"><I>slot specifiers</I></A> for a given <A REL=DEFINITION HREF="26_glo_s.htm#slot"><I>slot</I></A> name are ordered from most specific to least specific, according to the order in C's <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 define them. All references to the specificity of <A REL=DEFINITION HREF="26_glo_s.htm#slot_specifier"><I>slot specifiers</I></A> immediately below refers to this ordering. <P><DD>
|
||
|
<DT>* The allocation of a <A REL=DEFINITION HREF="26_glo_s.htm#slot"><I>slot</I></A> is controlled by the most specific <A REL=DEFINITION HREF="26_glo_s.htm#slot_specifier"><I>slot specifier</I></A>. If the most specific <A REL=DEFINITION HREF="26_glo_s.htm#slot_specifier"><I>slot specifier</I></A> does not contain an <TT>:allocation</TT> slot option, <TT>:instance</TT> is used. Less specific <A REL=DEFINITION HREF="26_glo_s.htm#slot_specifier"><I>slot specifiers</I></A> do not affect the allocation. <P><DD>
|
||
|
<DT>* The default initial value form for a <A REL=DEFINITION HREF="26_glo_s.htm#slot"><I>slot</I></A> is the value of the <TT>:initform</TT> slot option in the most specific <A REL=DEFINITION HREF="26_glo_s.htm#slot_specifier"><I>slot specifier</I></A> that contains one. If no <A REL=DEFINITION HREF="26_glo_s.htm#slot_specifier"><I>slot specifier</I></A> contains an <TT>:initform</TT> slot option, the <A REL=DEFINITION HREF="26_glo_s.htm#slot"><I>slot</I></A> has no default initial value form. <P><DD>
|
||
|
<DT>* The contents of a <A REL=DEFINITION HREF="26_glo_s.htm#slot"><I>slot</I></A> will always be of type <TT>(and T</TT>1<TT> ... T</TT>n<TT>)</TT> where T1 ...Tn are the values of the <TT>:type</TT> slot options contained in all of the <A REL=DEFINITION HREF="26_glo_s.htm#slot_specifier"><I>slot specifiers</I></A>. If no <A REL=DEFINITION HREF="26_glo_s.htm#slot_specifier"><I>slot specifier</I></A> contains the <TT>:type</TT> slot option, the contents of the <A REL=DEFINITION HREF="26_glo_s.htm#slot"><I>slot</I></A> will always be of <A REL=DEFINITION HREF="26_glo_t.htm#type"><I>type</I></A> <A REL=DEFINITION HREF="t_t.htm#t"><B>t</B></A>. The consequences of attempting to store in a <A REL=DEFINITION HREF="26_glo_s.htm#slot"><I>slot</I></A> a value that does not satisfy the <A REL=DEFINITION HREF="26_glo_t.htm#type"><I>type</I></A> of the <A REL=DEFINITION HREF="26_glo_s.htm#slot"><I>slot</I></A> are undefined. <P><DD>
|
||
|
<DT>* The set of initialization arguments that initialize a given <A REL=DEFINITION HREF="26_glo_s.htm#slot"><I>slot</I></A> is the union of the initialization arguments declared in the <TT>:initarg</TT> slot options in all the <A REL=DEFINITION HREF="26_glo_s.htm#slot_specifier"><I>slot specifiers</I></A>. <P><DD>
|
||
|
<DT>* The <A REL=DEFINITION HREF="26_glo_d.htm#documentation_string"><I>documentation string</I></A> for a <A REL=DEFINITION HREF="26_glo_s.htm#slot"><I>slot</I></A> is the value of the <TT>:documentation</TT> slot option in the most specific <A REL=DEFINITION HREF="26_glo_s.htm#slot"><I>slot</I></A> specifier that contains one. If no <A REL=DEFINITION HREF="26_glo_s.htm#slot_specifier"><I>slot specifier</I></A> contains a <TT>:documentation</TT> slot option, the <A REL=DEFINITION HREF="26_glo_s.htm#slot"><I>slot</I></A> has no <A REL=DEFINITION HREF="26_glo_d.htm#documentation_string"><I>documentation string</I></A>. <P><DD>
|
||
|
<P></DL><P>
|
||
|
A consequence of the allocation rule is that a <A REL=DEFINITION HREF="26_glo_s.htm#shared_slot"><I>shared slot</I></A> can be <I>shadowed</I>. For example, if a class C1 defines a <A REL=DEFINITION HREF="26_glo_s.htm#slot"><I>slot</I></A> named S whose value for the <TT>:allocation</TT> slot option is <TT>:class</TT>, that <A REL=DEFINITION HREF="26_glo_s.htm#slot"><I>slot</I></A> is <A REL=DEFINITION HREF="26_glo_a.htm#accessible"><I>accessible</I></A> in <A REL=DEFINITION HREF="26_glo_i.htm#instance"><I>instances</I></A> of C1 and all of its <A REL=DEFINITION HREF="26_glo_s.htm#subclass"><I>subclasses</I></A>. However, if C2 is a <A REL=DEFINITION HREF="26_glo_s.htm#subclass"><I>subclass</I></A> of C1 and also defines a <A REL=DEFINITION HREF="26_glo_s.htm#slot"><I>slot</I></A> named S, C1's <A REL=DEFINITION HREF="26_glo_s.htm#slot"><I>slot</I></A> is not shared by <A REL=DEFINITION HREF="26_glo_i.htm#instance"><I>instances</I></A> of C2 and its <A REL=DEFINITION HREF="26_glo_s.htm#subclass"><I>subclasses</I></A>. When a class C1 defines a <A REL=DEFINITION HREF="26_glo_s.htm#shared_slot"><I>shared slot</I></A>, any subclass C2 of C1 will share this single <A REL=DEFINITION HREF="26_glo_s.htm#slot"><I>slot</I></A> unless the <A REL=DEFINITION HREF="m_defcla.htm#defclass"><B>defclass</B></A> form for C2 specifies a <A REL=DEFINITION HREF="26_glo_s.htm#slot"><I>slot</I></A> of the same <A REL=DEFINITION HREF="26_glo_n.htm#name"><I>name</I></A> or there is a <A REL=DEFINITION HREF="26_glo_s.htm#superclass"><I>superclass</I></A> of C2 that precedes C1 in the <A REL=DEFINITION HREF="26_glo_c.htm#class_precedence_list"><I>class precedence list</I></A> of C2 that defines a <A REL=DEFINITION HREF="26_glo_s.htm#slot"><I>slot</I></A> of the same name. <P>
|
||
|
A consequence of the type rule is that the value of a <A REL=DEFINITION HREF="26_glo_s.htm#slot"><I>slot</I></A> satisfies the type constraint of each <A REL=DEFINITION HREF="26_glo_s.htm#slot_specifier"><I>slot specifier</I></A> that contributes to that <A REL=DEFINITION HREF="26_glo_s.htm#slot"><I>slot</I></A>. Because the result of attempting to store in a <A REL=DEFINITION HREF="26_glo_s.htm#slot"><I>slot</I></A> a value that does not satisfy the type constraint for the <A REL=DEFINITION HREF="26_glo_s.htm#slot"><I>slot</I></A> is undefined, the value in a <A REL=DEFINITION HREF="26_glo_s.htm#slot"><I>slot</I></A> might fail to satisfy its type constraint. <P>
|
||
|
The <TT>:reader</TT>, <TT>:writer</TT>, and <TT>:accessor</TT> slot options create <A REL=DEFINITION HREF="26_glo_m.htm#method"><I>methods</I></A> rather than define the characteristics of a <A REL=DEFINITION HREF="26_glo_s.htm#slot"><I>slot</I></A>. Reader and writer <A REL=DEFINITION HREF="26_glo_m.htm#method"><I>methods</I></A> are inherited in the sense described in <A REL=CHILD HREF="07_fg.htm">Section 7.6.7 (Inheritance of Methods)</A>. <P>
|
||
|
<A REL=DEFINITION HREF="26_glo_m.htm#method"><I>Methods</I></A> that <A REL=DEFINITION HREF="26_glo_a.htm#access"><I>access</I></A> <A REL=DEFINITION HREF="26_glo_s.htm#slot"><I>slots</I></A> use only the name of the <A REL=DEFINITION HREF="26_glo_s.htm#slot"><I>slot</I></A> and the <A REL=DEFINITION HREF="26_glo_t.htm#type"><I>type</I></A> of the <A REL=DEFINITION HREF="26_glo_s.htm#slot"><I>slot</I></A>'s value. Suppose a <A REL=DEFINITION HREF="26_glo_s.htm#superclass"><I>superclass</I></A> provides a <A REL=DEFINITION HREF="26_glo_m.htm#method"><I>method</I></A> that expects to <A REL=DEFINITION HREF="26_glo_a.htm#access"><I>access</I></A> a <A REL=DEFINITION HREF="26_glo_s.htm#shared_slot"><I>shared slot</I></A> of a given <A REL=DEFINITION HREF="26_glo_n.htm#name"><I>name</I></A>, and a <A REL=DEFINITION HREF="26_glo_s.htm#subclass"><I>subclass</I></A> defines a <A REL=DEFINITION HREF="26_glo_l.htm#local_slot"><I>local slot</I></A> with the same <A REL=DEFINITION HREF="26_glo_n.htm#name"><I>name</I></A>. If the <A REL=DEFINITION HREF="26_glo_m.htm#method"><I>method</I></A> provided by the <A REL=DEFINITION HREF="26_glo_s.htm#superclass"><I>superclass</I></A> is used on an <A REL=DEFINITION HREF="26_glo_i.htm#instance"><I>instance</I></A> of the <A REL=DEFINITION HREF="26_glo_s.htm#subclass"><I>subclass</I></A>, the <A REL=DEFINITION HREF="26_glo_m.htm#method"><I>method</I></A> <A REL=DEFINITION HREF="26_glo_a.htm#access"><I>accesses</I></A> the <A REL=DEFINITION HREF="26_glo_l.htm#local_slot"><I>local slot</I></A>. <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>
|