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.
From: Barry Margolin
Subject: Re: How to specify the default superclass for instances of a metaclass
Date:
Message-ID: <8laWa.3$hu1.2@news.level3.com>
In article <··············@ID-131024.news.uni-berlin.de>,
Simon Katz <·····@nomistech.com> 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.
You control this in your metaclass's definition. Read the AMOP.
--
Barry Margolin, ··············@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.
From: Kenny Tilton
Subject: Re: How to specify the default superclass for instances of a metaclass
Date:
Message-ID: <3F29B5A6.7000808@nyc.rr.com>
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.
--
kenny tilton
clinisys, inc
http://www.tilton-technology.com/
---------------------------------------------------------------
"Everything is a cell." -- Alan Kay
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.
From: Kenny Tilton
Subject: Re: How to specify the default superclass for instances of a metaclass
Date:
Message-ID: <3F2A4640.8050908@nyc.rr.com>
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.
--
kenny tilton
clinisys, inc
http://www.tilton-technology.com/
---------------------------------------------------------------
"Everything is a cell." -- Alan Kay
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.
From: Kenny Tilton
Subject: Re: How to specify the default superclass for instances of a metaclass
Date:
Message-ID: <3F2A74C5.2080002@nyc.rr.com>
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.
--
kenny tilton
clinisys, inc
http://www.tilton-technology.com/
---------------------------------------------------------------
"Everything is a cell." -- Alan Kay
From: Steven M. Haflich
Subject: Re: How to specify the default superclass for instances of a metaclass
Date:
Message-ID: <3F2A8456.60709@alum.mit.edu>
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.
From: james anderson
Subject: Re: How to specify the default superclass for instances of a metaclass
Date:
Message-ID: <3F2AF8B5.4A7ABCC4@setf.de>
wouldn't one need something more like a member-if with subtype predicate?
"Steven M. Haflich" wrote:
>
> 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 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.