[Prev][Next][Index][Thread]

Re: Need help with Class-Allocated Slots



In article <m3zoo8p02k.fsf@soma.andreas.org>, Andreas Bogk 
<andreas@andreas.org> wrote:

> "Scott McKay" <swm@mediaone.net> writes:
> 
> > During the design of Dylan, I proposed that class slots be accessible
> > by calling the accessor on the class object itself, but Moon didn't 
> > like
> > it because it confuses class vs. instance.  I agree with Moon on the
> > exact point, but I still think that the semantics of my dumb-ass 
> > proposal
> > are well enough understood, that it is probably reasonable.
> 
> Maybe it's time to resurrect the Dylan Language discussion at
> 
> http://www.isr.com/dylan/dylan-language/
> 
> I agree that it should be possible to access class slots without
> having an instance.
> 
> Andreas


I'm actually surprised this is even being considered.  The idea that 
class slots belong to the class itself is incorrect, though widely held.

Each class is an instance of <class>.  Conceptually, the lines

-------------------------------------
<my-class>.my-class-slot;
my-class-slot-getter (<my-class>);
-------------------------------------

imply that <my-class> has a slot called my-class-slot.  But it doesn't!  
<my-class> is an instance of <class>, not a sub-class of <class>.  The 
only slots that <my-class> has are the slots that <class> has, and 
<class> does not have the my-class-slot slot (...umm...yeah...).

Do y'all really want to muddy up Dylan's pristine conceptual waters like 
that?  (It really is much more pristine in my head than in English.)

Of course, it is certainly possible.  You could write an getter that 
specializes on a particular instance of the class, like so:

-------------------------------------
define method my-class-slot-getter (an-instance :: <class> == <my-class>)
  an-instance.my-class-slot;
end;
-------------------------------------

But I'd rather have the pristine waters, thank you.

It's really the same principle as Dylan's singletons.  You can make as 
many instances of a singleton as you like.  It's just that all those 
instances refer to the same object.  Similarly, you can make as many 
instances of a class slot as you like, they just all refer to the same 
object.

Thank you, and good night...



Follow-Ups: References: