<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">Thanks Shanon, <div class=""><br class=""></div><div class="">That was the clearest explanation for the puzzling VALIDATE-SUPERCLASS that I have ever seen!</div><div class=""><br class=""></div><div class="">- DM<br class=""><div><br class=""><blockquote type="cite" class=""><div class="">On Mar 4, 2021, at 11:50 PM, Shannon Spires <<a href="mailto:svs@bearlanding.com" class="">svs@bearlanding.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class="">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" class="">
<div text="#000000" bgcolor="#FFFFFF" class="">
> So it makes no sense to create an instance of COUNTED-CLASS
which inherits from RECTANGLE.<br class="">
<br class="">
Sure it does. 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 class="">
<br class="">
The equivalent (and more conventional) definition of <font face="monospace" class="">counted-rectangle</font> would be<br class="">
<font face="monospace" class=""><br class="">
(defclass counted-rectangle (rectangle)<br class="">
()<br class="">
(:metaclass counted-class))</font><br class="">
<br class="">
and this makes perfect sense.<br class="">
<br class="">
What doesn't work in the example is that <font face="monospace" class="">rectangle</font>
and <font face="monospace" class="">counted-rectangle</font> have different
metaclasses. Any time class A inherits from class B, they both
should be instances of the same metaclass. This is the piece of the
puzzle that AMOP gets wrong because the book was written before this
rule* was established. It's also the reason I dislike using special
metaclasses: The semantics of two classes that are instances of
different metaclasses inheriting from one another are ... not
well-defined. That means every time you use a special metaclass you
have to define all your classes in that hierarchy with the
:metaclass argument.<br class="">
<blockquote class="">*It's more a convention than a rule. It makes
implementors' lives much easier knowing that two inheriting class
metaobjects are of the same metaclass. One could fix this problem
with a <font face="monospace" class="">validate-superclass</font> method
but whether the resulting class metaobject would actually work is
implementation-specific:<br class="">
<br class="">
<font face="monospace" class="">(defmethod validate-superclass ((class
counted-class) (superclass standard-class))</font><br class="">
<font face="monospace" class=""> t)</font><br class="">
<br class="">
That works on Lispworks but not CCL or SBCL, because they're both
buggy about how and where they call <font face="monospace" class="">validate-superclass</font>
(see below). This is not the best solution. Here be dragons.<br class="">
</blockquote>
<br class="">
The best solution which works reliably for all implementations is to
redefine rectangle as:<br class="">
<br class="">
<font face="monospace" class="">(defclass rectangle ()<br class="">
((height :initform 0.0 :initarg :height)<br class="">
(width :initform 0.0 :initarg :width))<br class="">
(:metaclass counted-class))</font><br class="">
<br class="">
<b class="">But</b> even this is not enough, because there's a subtle bug the
way CCL and SBCL call <font face="monospace" class="">validate-superclass</font>.
The above definition of <font face="monospace" class="">rectangle</font>
throws an error:<br class="">
<font face="monospace" class="">> Error: The class #<STANDARD-CLASS
STANDARD-OBJECT> was specified as a<br class="">
> super-class of the class #<COUNTED-CLASS
RECTANGLE>;<br class="">
> but the meta-classes #<STANDARD-CLASS
STANDARD-CLASS> and<br class="">
> #<STANDARD-CLASS COUNTED-CLASS> are
incompatible.<br class="">
> 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 class="">
</font><br class="">
This error is ridiculous (and a bug) because <font face="monospace" class="">STANDARD-OBJECT</font>
is already a superclass of every CLOS instance (including class
metaobjects). This bug occurs in both CCL and SBCL but not
Lispworks.<br class="">
<br class="">
The fix is to define<br class="">
<br class="">
<font face="monospace" class="">(defmethod <a class="moz-txt-link-freetext" href="ccl::validate-superclass">ccl::validate-superclass</a> ((c1
standard-class) (c2 standard-object))<br class="">
t)</font><br class="">
<br class="">
[This is not the absolute best way to fix the problem but it works.
The real fix is to ensure that CCL and SBCL only call <font face="monospace" class="">validate-superclass</font> after the class
metaobjects in question are initialized enough that they know what
they are instances <i class="">of</i>, and also figure out why this error
only happens on special metaclasses. I'll leave that for another
day.]<br class="">
<br class="">
So a complete solution--using the unorthodox definition style of the
AMOP example--is as follows:<br class="">
<br class="">
<font face="monospace" class="">#+CCL<br class="">
(defmethod <a class="moz-txt-link-freetext" href="ccl:validate-superclass">ccl:validate-superclass</a> ((c1 standard-class) (c2
standard-object))<br class="">
"Must define this anytime you're using special metaclasses in
CCL."<br class="">
t)<br class="">
<br class="">
#+SBCL<br class="">
(defmethod sb-mop:validate-superclass ((c1 standard-class) (c2
standard-object))<br class="">
"Must define this anytime you're using special metaclasses in
SBCL."<br class="">
t)<br class="">
<br class="">
(defclass counted-class (standard-class)<br class="">
((counter :initform 0)))<br class="">
<br class="">
(defclass rectangle ()<br class="">
((height :initform 0.0 :initarg :height)<br class="">
(width :initform 0.0 :initarg :width))<br class="">
(:metaclass counted-class))<br class="">
<br class="">
; A goofy way to define a class, but it demonstrates dynamic class
creation<br class="">
(setf (find-class 'counted-rectangle)<br class="">
(make-instance 'counted-class<br class="">
:name 'counted-rectangle<br class="">
:direct-superclasses (list (find-class 'rectangle))<br class="">
:direct-slots ()))<br class="">
</font><br class="">
One more comment: This is a bad example on the part of AMOP but for
a different reason than Ron described. If you really want a
counted-class, using a class-allocated slot is a much better
approach. That way you don't need all this metaclass nonsense.<br class="">
<br class="">
-SS<font face="monospace" class=""><br class="">
<br class="">
<br class="">
</font>On 3/4/21 3:31 PM, Ron Garret wrote:<br class="">
<blockquote type="cite" cite="mid:AC81379F-82CE-4C90-995D-FF1729A8B2DE@flownet.com" class="">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" class="">
The first thing to do is to see if a different CL implementation
gives the same error:
<div class=""><br class="">
</div>
<div class="">
<div style="margin: 0px; font-size: 10px; font-family: Monaco;" class="">➔
sbcl</div>
<div style="margin: 0px; font-size: 10px; font-family: Monaco;" class="">This
is SBCL 1.1.9, an implementation of ANSI Common Lisp.</div>
<div style="margin: 0px; font-size: 10px; font-family: Monaco;" class="">More
information about SBCL is available at <<a href="http://www.sbcl.org/" moz-do-not-send="true" class="">http://www.sbcl.org/</a>>.</div>
<div style="margin: 0px; font-size: 10px; font-family: Monaco;
min-height: 14px;" class=""><br class="">
</div>
<div style="margin: 0px; font-size: 10px; font-family: Monaco;" class="">SBCL
is free software, provided as is, with absolutely no warranty.</div>
<div style="margin: 0px; font-size: 10px; font-family: Monaco;" class="">It
is mostly in the public domain; some portions are provided
under</div>
<div style="margin: 0px; font-size: 10px; font-family: Monaco;" class="">BSD-style
licenses. See the CREDITS and COPYING files in the</div>
<div style="margin: 0px; font-size: 10px; font-family: Monaco;" class="">distribution
for more information.</div>
<div style="margin: 0px; font-size: 10px; font-family: Monaco;" class="">(defclass
rectangle ()</div>
<div style="margin: 0px; font-size: 10px; font-family: Monaco;" class="">
((height :initform 0.0 :initarg :height)</div>
<div style="margin: 0px; font-size: 10px; font-family: Monaco;" class="">
(width :initform 0.0 :initarg :width)))</div>
<div style="margin: 0px; font-size: 10px; font-family: Monaco;
min-height: 14px;" class=""><br class="">
</div>
<div style="margin: 0px; font-size: 10px; font-family: Monaco;" class="">#<STANDARD-CLASS
RECTANGLE></div>
<div style="margin: 0px; font-size: 10px; font-family: Monaco;" class="">(defclass
counted-class (standard-class)</div>
<div style="margin: 0px; font-size: 10px; font-family: Monaco;" class="">
((counter :initform 0)))</div>
<div style="margin: 0px; font-size: 10px; font-family: Monaco;
min-height: 14px;" class=""><br class="">
</div>
<div style="margin: 0px; font-size: 10px; font-family: Monaco;" class="">#<STANDARD-CLASS
COUNTED-CLASS></div>
<div style="margin: 0px; font-size: 10px; font-family: Monaco;" class="">(make-instance
'counted-class</div>
<div style="margin: 0px; font-size: 10px; font-family: Monaco;" class="">
:name 'counted-rectangle</div>
<div style="margin: 0px; font-size: 10px; font-family: Monaco;" class="">
:direct-superclasses (list (find-class 'rectangle))</div>
<div style="margin: 0px; font-size: 10px; font-family: Monaco;" class="">
:direct-slots ())</div>
<div style="margin: 0px; font-size: 10px; font-family: Monaco;
min-height: 14px;" class=""><br class="">
</div>
<div style="margin: 0px; font-size: 10px; font-family: Monaco;" class="">debugger
invoked on a SIMPLE-ERROR:</div>
<div style="margin: 0px; font-size: 10px; font-family: Monaco;" class="">
The class #<STANDARD-CLASS RECTANGLE> was specified as a
super-class of the</div>
<div style="margin: 0px; font-size: 10px; font-family: Monaco;" class="">
class #<COUNTED-CLASS COUNTED-RECTANGLE>, but the
meta-classes</div>
<div style="margin: 0px; font-size: 10px; font-family: Monaco;" class="">
#<STANDARD-CLASS STANDARD-CLASS> and #<STANDARD-CLASS
COUNTED-CLASS> are</div>
<div style="margin: 0px; font-size: 10px; font-family: Monaco;" class="">
incompatible. Define a method for SB-MOP:VALIDATE-SUPERCLASS
to avoid this</div>
<div style="margin: 0px; font-size: 10px; font-family: Monaco;" class="">
error.</div>
</div>
<div class=""><br class="">
</div>
<div class="">So this appears to be a bug in the MOP book. And, if you
think about it, the example in the book really doesn’t make
sense. COUNTED-CLASS is a metaclass, i.e. all of its instances
are classes. But RECTANGLE is not a meta-class, it is a class.
All of its instances are rectangles, which are not classes. So
it makes no sense to create an instance of COUNTED-CLASS which
inherits from RECTANGLE. The instances of such a class would
have to be both classes and rectangles, and that’s not possible.</div>
<div class=""><br class="">
</div>
<div class="">rg</div>
<div class=""><br class="">
<div class="">
<div class="">On Mar 4, 2021, at 2:07 PM, Paul Krueger <<a href="mailto:plkrueger@comcast.net" moz-do-not-send="true" class="">plkrueger@comcast.net</a>>
wrote:</div>
<br class="Apple-interchange-newline">
<blockquote type="cite" class="">
<meta http-equiv="Content-Type" content="text/html;
charset=UTF-8" class="">
<div style="word-wrap: break-word; -webkit-nbsp-mode: space;
line-break: after-white-space;" class=""><span style="font-family: Monaco; font-size: 12px;" class="">I
was trying to do a little MOP hacking and when what I
was trying to do got errors I went back to “The Art of
the Metaobject Protocol” and ran an example from there
to see if it encountered similar errors, which it did
(most of this from p. 72 of the book):</span><br style="font-family: Monaco; font-size: 12px;" class="">
<br style="font-family: Monaco; font-size: 12px;" class="">
<span style="font-family: Monaco; font-size: 12px;" class="">I’m running Clozure Common Lisp Version 1.11.6
(v1.11.6) DarwinX8664</span><br style="font-family:
Monaco; font-size: 12px;" class="">
<br style="font-family: Monaco; font-size: 12px;" class="">
<span style="font-family: Monaco; font-size: 12px;" class="">? (defclass rectangle ()</span><br style="font-family: Monaco; font-size: 12px;" class="">
<span style="font-family: Monaco; font-size: 12px;" class=""> ((height :initform 0.0 :initarg :height)</span><br style="font-family: Monaco; font-size: 12px;" class="">
<span style="font-family: Monaco; font-size: 12px;" class=""> (width :initform 0.0 :initarg :width)))</span><br style="font-family: Monaco; font-size: 12px;" class="">
<span style="font-family: Monaco; font-size: 12px;" class="">#<STANDARD-CLASS RECTANGLE></span><br style="font-family: Monaco; font-size: 12px;" class="">
<span style="font-family: Monaco; font-size: 12px;" class="">? (defclass counted-class (standard-class)</span><br style="font-family: Monaco; font-size: 12px;" class="">
<span style="font-family: Monaco; font-size: 12px;" class=""> ((counter :initform 0)))</span><br style="font-family: Monaco; font-size: 12px;" class="">
<span style="font-family: Monaco; font-size: 12px;" class="">#<STANDARD-CLASS COUNTED-CLASS></span><br style="font-family: Monaco; font-size: 12px;" class="">
<span style="font-family: Monaco; font-size: 12px;" class="">? (setf (find-class 'counted-rectangle)</span><br style="font-family: Monaco; font-size: 12px;" class="">
<span style="font-family: Monaco; font-size: 12px;" class=""> (make-instance 'counted-class</span><br style="font-family: Monaco; font-size: 12px;" class="">
<span style="font-family: Monaco; font-size: 12px;" class=""> :name 'counted-rectangle</span><br style="font-family: Monaco; font-size: 12px;" class="">
<span style="font-family: Monaco; font-size: 12px;" class=""> :direct-superclasses (list (find-class
'rectangle))</span><br style="font-family: Monaco;
font-size: 12px;" class="">
<span style="font-family: Monaco; font-size: 12px;" class=""> :direct-slots ()))</span><br style="font-family: Monaco; font-size: 12px;" class="">
<blockquote type="cite" style="font-family: Monaco;
font-size: 12px;" class="">Error: The class
#<STANDARD-CLASS RECTANGLE> was specified as a<br class="">
super-class of the class #<COUNTED-CLASS
COUNTED-RECTANGLE>;<br class="">
but the meta-classes #<STANDARD-CLASS
STANDARD-CLASS> and<br class="">
#<STANDARD-CLASS COUNTED-CLASS> are
incompatible.<br class="">
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 class="">
Type cmd-. to abort, cmd-\ for a list of available
restarts.<br class="">
Type :? for other options.<br class="">
</blockquote>
<span style="font-family: Monaco; font-size: 12px;" class="">1 > </span><br style="font-family: Monaco;
font-size: 12px;" class="">
<span style="font-family: Monaco; font-size: 12px;" class="">?</span><br style="font-family: Monaco;
font-size: 12px;" class="">
<br style="font-family: Monaco; font-size: 12px;" class="">
<span style="font-family: Monaco; font-size: 12px;" class="">My question is whether this is a problem with
CCL’s implementation or a spec change of some sort that
invalidates the example from the book. It’s not clear to
me how you could ever employ meta-classes without
getting this sort of error in CCL, so if this isn’t a
bug, what’s the work-around?</span><br style="font-family: Monaco; font-size: 12px;" class="">
<br style="font-family: Monaco; font-size: 12px;" class="">
<span style="font-family: Monaco; font-size: 12px;" class="">Thanks ...</span></div>
_______________________________________________<br class="">
Openmcl-devel mailing list<br class="">
<a href="mailto:Openmcl-devel@clozure.com" moz-do-not-send="true" class="">Openmcl-devel@clozure.com</a><br class="">
<a class="moz-txt-link-freetext" href="https://lists.clozure.com/mailman/listinfo/openmcl-devel">https://lists.clozure.com/mailman/listinfo/openmcl-devel</a><br class="">
</blockquote>
</div>
<br class="">
</div>
<br class="">
<fieldset class="mimeAttachmentHeader"></fieldset>
<pre class="moz-quote-pre" wrap="">_______________________________________________
Openmcl-devel mailing list
<a class="moz-txt-link-abbreviated" href="mailto:Openmcl-devel@clozure.com">Openmcl-devel@clozure.com</a>
<a class="moz-txt-link-freetext" href="https://lists.clozure.com/mailman/listinfo/openmcl-devel">https://lists.clozure.com/mailman/listinfo/openmcl-devel</a>
</pre>
</blockquote>
<br class="">
</div>
_______________________________________________<br class="">Openmcl-devel mailing list<br class=""><a href="mailto:Openmcl-devel@clozure.com" class="">Openmcl-devel@clozure.com</a><br class="">https://lists.clozure.com/mailman/listinfo/openmcl-devel<br class=""></div></blockquote></div><br class=""></div></body></html>