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.
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.
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
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.
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.
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.
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.
> 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.
> 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.