From: Frode Vatvedt Fjeld
Subject: clos class specialization
Date: 
Message-ID: <2h3drrr9zu.fsf@dslab7.cs.uit.no>
I find myself often designing classes such that particular derived
subclasses are to have a certain constant value for a (inherited)
slot.

How is this best expressed in CL/CLOS?

What I've done is this:

(defclass super ()
  (a-slot more-slots ..))

and then by design I have a subclass where every instance share
particular value for "a-slot":

(defclass sub (super)
  ((a-slot :allocation :class
           :initform "This is a sub")
   more-slots ..))


This almost works, but not too nicely. For example, initform is only
evaluated when class sub is defined the first time.

It seems to me that this would be a common kind of design, so I
thought someone with more CLOS experiece would know what is the better
way to do it.


Thanks,
-- 
Frode Vatvedt Fjeld

From: Stig Hemmer
Subject: Re: clos class specialization
Date: 
Message-ID: <ekv7lh3v4ku.fsf@verden.pvv.ntnu.no>
Frode Vatvedt Fjeld <······@acm.org> writes:
> I find myself often designing classes such that particular derived
> subclasses are to have a certain constant value for a (inherited)
> slot.

May I suggest not implementing this as a slot, but as a generic
function?

Stig Hemmer,
Jack of a Few Trades.
From: Barry Margolin
Subject: Re: clos class specialization
Date: 
Message-ID: <PN%h4.64$471.1101@burlma1-snr2>
In article <···············@verden.pvv.ntnu.no>,
Stig Hemmer  <····@pvv.ntnu.no> wrote:
>Frode Vatvedt Fjeld <······@acm.org> writes:
>> I find myself often designing classes such that particular derived
>> subclasses are to have a certain constant value for a (inherited)
>> slot.
>
>May I suggest not implementing this as a slot, but as a generic
>function?

In fact, you can do both.  The recommended way to access slots is by using
:ACCESSOR to automatically define a method to do it.  Subclasses can define
their own method for this generic function, overriding the one that was
created to access the slot.

-- 
Barry Margolin, ······@bbnplanet.com
GTE Internetworking, Powered by BBN, Burlington, 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: Frode Vatvedt Fjeld
Subject: Re: clos class specialization
Date: 
Message-ID: <2hsnzrpc9m.fsf@dslab7.cs.uit.no>
Thanks to both of you :-)

-- 
Frode Vatvedt Fjeld