<html>
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=windows-1252">
</head>
<body text="#000000" bgcolor="#FFFFFF">
See comments inline.<br>
-SS<br>
<br>
<div class="moz-cite-prefix">On 3/5/21 9:25 AM, Ron Garret wrote:<br>
</div>
<blockquote type="cite"
cite="mid:D848EA75-B628-46F7-BA96-0AEEE11FC583@flownet.com">
<meta http-equiv="Content-Type" content="text/html;
charset=windows-1252">
<br>
<div>
<div>On Mar 4, 2021, at 10:50 PM, Shannon Spires <<a
href="mailto:svs@bearlanding.com" moz-do-not-send="true">svs@bearlanding.com</a>>
wrote:</div>
<br class="Apple-interchange-newline">
<blockquote type="cite">
<meta http-equiv="Content-Type" content="text/html;
charset=windows-1252">
<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>?<br>
</div>
</blockquote>
</div>
</div>
</blockquote>
<br>
You haven't shown the definition of rectangle above. Let's include
that:<br>
<div><br>
<font face="monospace">Clozure Common Lisp Version 1.12-dev
(v1.12-dev.5-22-g0430f8db) DarwinX8664<br>
<br>
For more information about CCL, please see
<a class="moz-txt-link-freetext" href="http://ccl.clozure.com">http://ccl.clozure.com</a>.<br>
<br>
CCL is free software. It is distributed under the terms of the
Apache<br>
Licence, Version 2.0.<br>
? (defclass counted-class (standard-class)<br>
((counter :initform 0)))<br>
#<STANDARD-CLASS COUNTED-CLASS><br>
? (defclass rectangle ()<br>
((height :initform 0.0 :initarg :height)<br>
(width :initform 0.0 :initarg :width)))<br>
#<STANDARD-CLASS RECTANGLE><br>
? (defclass counted-rectangle (rectangle)<br>
()<br>
(:metaclass counted-class))<br>
> Error: The class #<STANDARD-CLASS RECTANGLE> was
specified as a<br>
> super-class of the class #<COUNTED-CLASS
COUNTED-RECTANGLE>;<br>
> but the meta-classes #<STANDARD-CLASS
STANDARD-CLASS> and<br>
> #<STANDARD-CLASS COUNTED-CLASS> are
incompatible.<br>
> While executing: #<a class="moz-txt-link-rfc2396E" href="CCL::STANDARD-KERNEL-METHODCCL::ENSURE-CLASS-INITIALIZED(CCL::SLOTS-CLASS)"><CCL::STANDARD-KERNEL-METHOD
CCL::ENSURE-CLASS-INITIALIZED (CCL::SLOTS-CLASS)></a>, in process
Listener(4).<br>
> Type cmd-. to abort, cmd-\ for a list of available
restarts.<br>
> Type :? for other options.<br>
1 > </font><br>
<br>
</div>
Oops. It doesn't work if rectangle's definition doesn't include <font
face="monospace">(:metaclass counted-class).</font><br>
<br>
But your point is valid because I didn't test for the case of
defining <font face="monospace">rectangle</font> <i>after</i>
defining <font face="monospace">counted-rectangle</font>. That
works even when <font face="monospace">rectangle</font> does <i>not</i>
include <font face="monospace">(:metaclass counted-class)</font>.
The order of class definitions shouldn't matter; I think that's
probably a bug.<br>
<br>
<blockquote type="cite"
cite="mid:D848EA75-B628-46F7-BA96-0AEEE11FC583@flownet.com">
<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>
</blockquote>
<br>
This is where it's important to use precise terminology.<br>
<br>
COUNTED-RECTANGLE is literally "The class metaobject named
COUNTED-RECTANGLE which happens to be an instance of COUNTED-CLASS,
and which also happens to inherit from RECTANGLE." This makes
perfect sense when one understands that COUNTED-RECTANGLE is a class
metaobject, because only class metaobjects can "inherit" from
anything. (Ordinary CLOS objects that are <i>not</i> class
metaobjects cannot "inherit" from anything. They are merely
instances of a single class, period. Although we might loosely say
things like "the LION named Sam inherits from CARNIVORE and
SAVANNAH-RESIDENT" that phrasing is not technically accurate; only
the class LION can inherit from CARNIVORE and SAVANNAH-RESIDENT. As
an instance of LION, Sam has no "inheritance" relationship with
anything (except perhaps his ancestor lions, but that's not the kind
of "inheritance" we're talking about here.))<br>
<br>
The <font face="monospace">:direct-superclasses</font> argument in
the AMOP example specifies the inheritance relationship for class
metaobjects. It expresses the same thing as <font face="monospace">(rectangle)</font>
below:<br>
<br>
<font face="monospace">(defclass counted-rectangle (rectangle)<br>
()<br>
(:metaclass counted-class))</font><br>
<br>
Which again makes perfect sense.<br>
<br>
<blockquote type="cite"
cite="mid:D848EA75-B628-46F7-BA96-0AEEE11FC583@flownet.com">
<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>
</blockquote>
<br>
It only works if you define RECTANGLE <i>after</i>
COUNTED-RECTANGLE. Which I think is probably a bug.<br>
<br>
<blockquote type="cite"
cite="mid:D848EA75-B628-46F7-BA96-0AEEE11FC583@flownet.com">
<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,</div>
</div>
</div>
</blockquote>
<br>
Nope. Again, <b><font face="monospace">:direct-superclasses</font></b><b>
is about the superclasses of the class metaobject; it is not about
the metaclass of the class metaobject.</b><b><br>
</b><br>
<span class="" style="font-family: Monaco;"></span><br>
<blockquote type="cite"
cite="mid:D848EA75-B628-46F7-BA96-0AEEE11FC583@flownet.com">
<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>
</blockquote>
<br>
</body>
</html>