75 lines
7 KiB
HTML
75 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 4.3.5.2</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="04_cea.htm">
|
|
<LINK REL=UP HREF="04_ce.htm">
|
|
<LINK REL=NEXT HREF="04_cf.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="04_cea.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Previous]" SRC="../Graphics/Prev.gif" ALIGN=Bottom></A><A REL=UP HREF="04_ce.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Up]" SRC="../Graphics/Up.gif" ALIGN=Bottom></A><A REL=NEXT HREF="04_cf.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Next]" SRC="../Graphics/Next.gif" ALIGN=Bottom></A></H1>
|
|
|
|
<HR>
|
|
|
|
<H2>
|
|
4.3.5.2 Examples of Class Precedence List Determination</H2> <P>
|
|
This example determines a <A REL=DEFINITION HREF="26_glo_c.htm#class_precedence_list"><I>class precedence list</I></A> for the class <TT>pie</TT>. The following <A REL=DEFINITION HREF="26_glo_c.htm#class"><I>classes</I></A> are defined: <P>
|
|
<PRE>
|
|
(defclass pie (apple cinnamon) ())
|
|
|
|
(defclass apple (fruit) ())
|
|
|
|
(defclass cinnamon (spice) ())
|
|
|
|
(defclass fruit (food) ())
|
|
|
|
(defclass spice (food) ())
|
|
|
|
(defclass food () ())
|
|
</PRE>
|
|
</TT> <P>
|
|
The set Spie = {<TT>pie, apple, cinnamon, fruit, spice, food, standard-object, t</TT>}. The set R = {<TT>(pie, apple), (apple, cinnamon), (apple, fruit), (cinnamon, spice), <BR>
|
|
(fruit, food), (spice, food), (food, standard-object), (standard-object, t)</TT>}. <P>
|
|
The class <TT>pie</TT> is not preceded by anything, so it comes first; the result so far is <TT>(pie)</TT>. Remove <TT>pie</TT> from S and pairs mentioning <TT>pie</TT> from R to get S = {<TT>apple, cinnamon, fruit, spice, food, standard-object, t</TT>} and R = {<TT>(apple, cinnamon), (apple, fruit), (cinnamon, spice),<BR>
|
|
(fruit, food), (spice, food), (food, standard-object), (standard-object, t)</TT>}. <P>
|
|
The class <TT>apple</TT> is not preceded by anything, so it is next; the result is <TT>(pie apple)</TT>. Removing <TT>apple</TT> and the relevant pairs results in S = {<TT>cinnamon, fruit, spice, food, standard-object, t</TT>} and R = {<TT>(cinnamon, spice), (fruit, food), (spice, food), (food, standard-object),<BR>
|
|
(standard-object, t)</TT>}. <P>
|
|
The classes <TT>cinnamon</TT> and <TT>fruit</TT> are not preceded by anything, so the one with a direct <A REL=DEFINITION HREF="26_glo_s.htm#subclass"><I>subclass</I></A> rightmost in the <A REL=DEFINITION HREF="26_glo_c.htm#class_precedence_list"><I>class precedence list</I></A> computed so far goes next. The class <TT>apple</TT> is a direct <A REL=DEFINITION HREF="26_glo_s.htm#subclass"><I>subclass</I></A> of <TT>fruit</TT>, and the class <TT>pie</TT> is a direct <A REL=DEFINITION HREF="26_glo_s.htm#subclass"><I>subclass</I></A> of <TT>cinnamon</TT>. Because <TT>apple</TT> appears to the right of <TT>pie</TT> in the <A REL=DEFINITION HREF="26_glo_c.htm#class_precedence_list"><I>class precedence list</I></A>, <TT>fruit</TT> goes next, and the result so far is <TT>(pie apple fruit)</TT>. S = {<TT>cinnamon, spice, food, standard-object, t</TT>}; R = {<TT>(cinnamon, spice), (spice, food),<BR>
|
|
(food, standard-object), (standard-object, t)</TT>}. <P>
|
|
The class <TT>cinnamon</TT> is next, giving the result so far as <TT>(pie apple fruit cinnamon)</TT>. At this point S = {<TT>spice, food, standard-object, t</TT>}; R = {<TT>(spice, food), (food, standard-object), (standard-object, t)</TT>}. <P>
|
|
The classes <TT>spice</TT>, <TT>food</TT>, <A REL=DEFINITION HREF="t_std_ob.htm#standard-object"><B>standard-object</B></A>, and <A REL=DEFINITION HREF="t_t.htm#t"><B>t</B></A> are added in that order, and the <A REL=DEFINITION HREF="26_glo_c.htm#class_precedence_list"><I>class precedence list</I></A> is <TT>(pie apple fruit cinnamon spice food standard-object t)</TT>. <P>
|
|
It is possible to write a set of <A REL=DEFINITION HREF="26_glo_c.htm#class"><I>class</I></A> definitions that cannot be ordered. For example: <P>
|
|
<PRE>
|
|
(defclass new-class (fruit apple) ())
|
|
|
|
(defclass apple (fruit) ())
|
|
</PRE>
|
|
</TT> <P>
|
|
The class <TT>fruit</TT> must precede <TT>apple</TT> because the local ordering of <A REL=DEFINITION HREF="26_glo_s.htm#superclass"><I>superclasses</I></A> must be preserved. The class <TT>apple</TT> must precede <TT>fruit</TT> because a <A REL=DEFINITION HREF="26_glo_c.htm#class"><I>class</I></A> always precedes its own <A REL=DEFINITION HREF="26_glo_s.htm#superclass"><I>superclasses</I></A>. When this situation occurs, an error is signaled, as happens here when the system tries to compute the <A REL=DEFINITION HREF="26_glo_c.htm#class_precedence_list"><I>class precedence list</I></A> of <TT>new-class</TT>. <P>
|
|
The following might appear to be a conflicting set of definitions: <P>
|
|
<PRE>
|
|
(defclass pie (apple cinnamon) ())
|
|
|
|
(defclass pastry (cinnamon apple) ())
|
|
|
|
(defclass apple () ())
|
|
|
|
(defclass cinnamon () ())
|
|
</PRE>
|
|
</TT> <P>
|
|
The <A REL=DEFINITION HREF="26_glo_c.htm#class_precedence_list"><I>class precedence list</I></A> for <TT>pie</TT> is <TT>(pie apple cinnamon standard-object t)</TT>. <P>
|
|
The <A REL=DEFINITION HREF="26_glo_c.htm#class_precedence_list"><I>class precedence list</I></A> for <TT>pastry</TT> is <TT>(pastry cinnamon apple standard-object t)</TT>. <P>
|
|
It is not a problem for <TT>apple</TT> to precede <TT>cinnamon</TT> in the ordering of the <A REL=DEFINITION HREF="26_glo_s.htm#superclass"><I>superclasses</I></A> of <TT>pie</TT> but not in the ordering for <TT>pastry</TT>. However, it is not possible to build a new <A REL=DEFINITION HREF="26_glo_c.htm#class"><I>class</I></A> that has both <TT>pie</TT> and <TT>pastry</TT> as <A REL=DEFINITION HREF="26_glo_s.htm#superclass"><I>superclasses</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>
|