Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to specify the default superclass for instances of a metaclass

10 views
Skip to first unread message

Simon Katz

unread,
Jul 31, 2003, 8:13:12 AM7/31/03
to
The standard's writeup of DEFCLASS says:

If the superclass list is empty, then the superclass
defaults depending on the metaclass, with standard-object
being the default for standard-class.

How can I specify a different superclass when the metaclass is one
that I've defined?

I know I can fiddle with the superclasses in the INITIALIZE-INSTANCE
and REINITIALIZE-INSTANCE methods on the metaclass, but the words
above suggest there might be an easier way.


Barry Margolin

unread,
Jul 31, 2003, 11:12:04 AM7/31/03
to
In article <bgb15e$mjl2g$1...@ID-131024.news.uni-berlin.de>,

You control this in your metaclass's definition. Read the AMOP.

--
Barry Margolin, barry.m...@level3.com
Level(3), Woburn, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.

Kenny Tilton

unread,
Jul 31, 2003, 8:37:17 PM7/31/03
to

FWIW, I never found an easier way, and I did look high and low thinking
there must be some . But I fiddled with SHARED-INITIALIZE so I only had
to fiddle once.


--

kenny tilton
clinisys, inc
http://www.tilton-technology.com/
---------------------------------------------------------------
"Everything is a cell." -- Alan Kay

Simon Katz

unread,
Aug 1, 2003, 5:04:46 AM8/1/03
to
Kenny Tilton wrote:
> Simon Katz wrote:
> > The standard's writeup of DEFCLASS says:
> >
> > If the superclass list is empty, then the superclass
> > defaults depending on the metaclass, with standard-object
> > being the default for standard-class.
> >
> > How can I specify a different superclass when the metaclass is one
> > that I've defined?
> >
> > I know I can fiddle with the superclasses in the
> > INITIALIZE-INSTANCE
> > and REINITIALIZE-INSTANCE methods on the metaclass, but the words
> > above suggest there might be an easier way.
>
> FWIW, I never found an easier way, and I did look high and low
> thinking there must be some . But I fiddled with SHARED-INITIALIZE
> so I only had to fiddle once.

AMOP p196: Portable programs must not define methods on
SHARED-INITIALIZE.

To avoid duplication I have a macro that computes the fiddled-with
list of superclasses and calls CALL-NEXT-METHOD, and I call this from
the :around methods on INITIALIZE-INSTANCE and REINITIALIZE-INSTANCE.


Kenny Tilton

unread,
Aug 1, 2003, 6:54:13 AM8/1/03
to

Simon Katz wrote:


> Kenny Tilton wrote:
>>FWIW, I never found an easier way, and I did look high and low
>>thinking there must be some . But I fiddled with SHARED-INITIALIZE
>>so I only had to fiddle once.
>
>
> AMOP p196: Portable programs must not define methods on
> SHARED-INITIALIZE.

Ah, right you are.

Steven M. Haflich

unread,
Aug 1, 2003, 10:00:36 AM8/1/03
to
Kenny Tilton wrote:
>
> Simon Katz wrote:
>
>> How can I specify a different superclass when the metaclass is one
>> that I've defined?
>
> FWIW, I never found an easier way, and I did look high and low thinking
> there must be some . But I fiddled with SHARED-INITIALIZE so I only had
> to fiddle once.

Don't forget that there is any entirely different approach than using a
specialized metaclass and the MOP: Write a simple customized macro that
expands into a defclass form with a fiddled superclass list. Or have
the expansion specify a customized metaclass _as_ _well_ _as_ a fiddled
superclass list.

Kenny Tilton

unread,
Aug 1, 2003, 10:12:44 AM8/1/03
to

Steven M. Haflich wrote:
> Kenny Tilton wrote:
> >
> > Simon Katz wrote:
> >
> >> How can I specify a different superclass when the metaclass is one
> >> that I've defined?
> >
> > FWIW, I never found an easier way, and I did look high and low thinking
> > there must be some . But I fiddled with SHARED-INITIALIZE so I only had
> > to fiddle once.
>
> Don't forget that there is any entirely different approach than using a
> specialized metaclass and the MOP: Write a simple customized macro that
> expands into a defclass form with a fiddled superclass list.

You mean?:

(defmacro defmodel (class directsupers slotspecs &rest options)
....
`(defclass ,class ,(or directsupers '(model-object))...


Good point. That's what I did when I backed off metaclasses for portability.

Steven M. Haflich

unread,
Aug 1, 2003, 11:15:36 AM8/1/03
to
Kenny Tilton wrote:

> You mean?:
>
> (defmacro defmodel (class directsupers slotspecs &rest options)
> ....
> `(defclass ,class ,(or directsupers '(model-object))...

Perhaps something like this is more powerful:

(defmacro defmodel (class directsupers slots &rest options)
...
`(defclass ,class
,(if (member 'model-object :directsupers)
directsupers
(append direct-supers '(model-object)))
,slots
,@options))

And of course, the macro could also check the options and supply
a default for the metaclass.

Macros and metaclasses both encapsulate code, but in very different
ways.

james anderson

unread,
Aug 1, 2003, 7:33:27 PM8/1/03
to

wouldn't one need something more like a member-if with subtype predicate?

Steven M. Haflich

unread,
Aug 2, 2003, 2:22:09 PM8/2/03
to
james anderson wrote:

> wouldn't one need something more like a member-if with subtype predicate?

I think not. Something like the suggested macro simply assures that the
model-object class is placed at the end of the superclass list if it is
not already present. There would be no conflict if some subclass of
model-object appears in the list. The class-precedence-list determination
algorithm handles this automatically.

What a subtype predicate would do is allow class objects to appear in the
superclass list in addition to class names, but presumably this freedon
isn't necessary in this usage.

0 new messages