<html><head><meta http-equiv="Content-Type" content="text/html charset=windows-1252"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><br><div><div>On Mar 4, 2021, at 10:50 PM, Shannon Spires <<a href="mailto:svs@bearlanding.com">svs@bearlanding.com</a>> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<div text="#000000" bgcolor="#FFFFFF">
> So it makes no sense to create an instance of COUNTED-CLASS
which inherits from RECTANGLE.<br>
<br>
Sure it does.</div></blockquote><div><br></div><div>No, it doesn’t :-)</div><br><blockquote type="cite"><div text="#000000" bgcolor="#FFFFFF">Any given class metaobject has two kinds of
relationships with other class metaobjects: It has an INSTANCE-OF
relationship with its metaclass and an ISA (or INHERITANCE)
relationship with its superclasses.<br></div></blockquote><div><br></div><div>Yes.</div><br><blockquote type="cite"><div text="#000000" bgcolor="#FFFFFF">
The equivalent (and more conventional) definition of <font face="monospace">counted-rectangle</font> would be<br>
<font face="monospace"><br>
(defclass counted-rectangle (rectangle)<br>
()<br>
(:metaclass counted-class))</font><br>
<br>
and this makes perfect sense.<br></div></blockquote><div><br></div><div>Yes. And it works:</div><div><br></div><div><blockquote type="cite"><div>Welcome to Clozure Common Lisp Version 1.11-r16812M (DarwinX8664)!</div><div>? (defclass counted-class (standard-class)</div><div> ((counter :initform 0)))</div><div>#<STANDARD-CLASS COUNTED-CLASS></div><div>? (defclass counted-rectangle (rectangle)</div><div> ()</div><div> (:metaclass counted-class))</div><div>#<COUNTED-CLASS COUNTED-RECTANGLE></div><div>? </div></blockquote><br></div><div>But that is not the same thing as creating “an instance of COUNTED-CLASS which inherits from RECTANGLE”:</div><div><br></div><div><blockquote type="cite"><div>? (class-of (find-class 'counted-rectangle))</div><div>#<STANDARD-CLASS COUNTED-CLASS></div></blockquote><blockquote type="cite"><div>? (class-direct-superclasses *)</div><div>(#<STANDARD-CLASS STANDARD-CLASS>)</div><div>? </div></blockquote><br></div><div>In this case, COUNTED-CLASS inherits only from STANDARD-CLASS, not from RECTANGLE. And that does indeed make sense.</div><div><br></div><blockquote type="cite"><div text="#000000" bgcolor="#FFFFFF">
What doesn't work in the example is that <font face="monospace">rectangle</font>
and <font face="monospace">counted-rectangle</font> have different
metaclasses.</div></blockquote><div><br></div><div>No, that’s not the problem. In the example as you’ve given it (not as the MOP book gives it), COUNTED-RECTANGLE has a metaclass of COUNTED-CLASS, and RECTANGLE (assuming you define it as the MOP book does) has a meta-class of STANDARD-CLASS. And all that works just fine.</div><div><br></div><div>The problem with the MOP example:</div><div><br></div><div><div text="#000000" bgcolor="#FFFFFF"><blockquote type="cite"><div class="" style="word-wrap: break-word; -webkit-nbsp-mode: space;"><span class="" style="font-family: Monaco;">? (setf (find-class 'counted-rectangle)</span><br class="" style="font-family: Monaco;"><span class="" style="font-family: Monaco;"> (make-instance 'counted-class</span><br class="" style="font-family: Monaco;"><span class="" style="font-family: Monaco;"> :name 'counted-rectangle</span><br class="" style="font-family: Monaco;"><span class="" style="font-family: Monaco;"> :direct-superclasses (list (find-class 'rectangle))</span><br class="" style="font-family: Monaco;"><span class="" style="font-family: Monaco;"> :direct-slots ()))</span></div></blockquote><br></div><div text="#000000" bgcolor="#FFFFFF">Is that it is trying to make the metaclass of COUNTED-CLASS be RECTANGLE, and that doesn’t work because RECTANGLE is not a metaclass, it is an *instance* of STANDARD-CLASS. STANDARD-CLASS can be a metaclass, but an *instance* of STANDARD-CLASS (with the RECTANGLE class is) cannot be.</div><div text="#000000" bgcolor="#FFFFFF"><br></div></div><blockquote type="cite"><div text="#000000" bgcolor="#FFFFFF"> Any time class A inherits from class B, they both
should be instances of the same metaclass.</div></blockquote><div><br></div><div>That is correct, but you’ve misapplied the rule. The problem is not that "rectangle and counted-rectangle have different metaclasses”. The problem in this case is that RECTANGLE and *COUNTED-CLASS* (not counted-rectangle) have different metaclasses. Having rectangle and counted-rectangle have different metaclasses works perfectly well, as the example above demonstrates.</div><div><br></div><div>Another way to illustrate what the problem actually is here:</div><div><br></div><div><div>? (typep (make-instance 'standard-class) 'class)</div><div>T</div><div><div>? (typep (make-instance 'counted-class) 'class)</div><div>T</div></div><div>? (typep (make-instance 'rectangle) 'class)</div><div>NIL</div><div><br></div><div>That is the reason that it makes no sense for RECTANGLE to be a DIRECT-SUPERCLASS of an instance of COUNTED-CLASS. An instance of COUNTED-CLASS is a class, but an instance of RECTANGLE is not. So an instance of the resulting chimera would have to be both a class and not a class.</div><div><br></div><div>But yeah, it gets pretty confusing.</div><div><br></div></div><div>rg</div><div><br></div></div></body></html>