From: Tunc Simsek
Subject: [CLOS/MOP] Allocation and access
Date: 
Message-ID: <Pine.SOL.4.10.10006281630070.9550-100000@tudor.EECS.Berkeley.EDU>
Regards,

I've some trouble understanding the MOP (The CLOS implementation of CLOS,
Kiczales):

a) The method ALLOCATE-INSTANCE (specialized to STANDARD-OBJECT)
  presumably allocates an instance with space for :instance slots.
  Then, where are the shared slots?  Does the property :location
  have any meaning for shared slots?

  This one may not have an answer:
  What makes an instance an instance?  

b) When accessing, the AMOP book reads that STANDARD-INSTANCE-ACCESS
   may be used to access a slot by its location.  Is it possible
   to write in the same way?

c) In SLOT-VALUE-USING-CLASS, what is the CLASS?  Is the class
   where the slot is defined or is it (SLOT-DEFINITION-CLASS <sd>)?


Thanks for any help,
Tunc

From: Thomas A. Russ
Subject: Re: [CLOS/MOP] Allocation and access
Date: 
Message-ID: <ymivgysea0i.fsf@sevak.isi.edu>
Answering off the top of my head, without a lot of experience in
particular implementations:

Tunc Simsek <······@tudor.EECS.Berkeley.EDU> writes:

> a) The method ALLOCATE-INSTANCE (specialized to STANDARD-OBJECT)
>   presumably allocates an instance with space for :instance slots.
>   Then, where are the shared slots?

I would imagine anywhere the implmentation chooses to put them.  One
common place would be in the class object, but there could be other
choices.

>   This one may not have an answer:
>   What makes an instance an instance?  

It is pretty much a definition.

> c) In SLOT-VALUE-USING-CLASS, what is the CLASS?  Is the class
>    where the slot is defined or is it (SLOT-DEFINITION-CLASS <sd>)?

The class in which the slot was defined.  The intent is to allow you to
special this method so that slot access will be handled in a different
way for particular classes.  This often incurs sometimes pretty stiff
performance penalties.

-- 
Thomas A. Russ,  USC/Information Sciences Institute          ···@isi.edu    
From: Tunc Simsek
Subject: Re: [CLOS/MOP] Allocation and access
Date: 
Message-ID: <395B9A99.2977F558@robotics.eecs.berkeley.edu>
"Thomas A. Russ" wrote:
> 
> Answering off the top of my head, without a lot of experience in
> particular implementations:
> 
> Tunc Simsek <······@tudor.EECS.Berkeley.EDU> writes:
> 
> > a) The method ALLOCATE-INSTANCE (specialized to STANDARD-OBJECT)
> >   presumably allocates an instance with space for :instance slots.
> >   Then, where are the shared slots?
> 
> I would imagine anywhere the implmentation chooses to put them.  One
> common place would be in the class object, but there could be other
> choices.

ok., that would check out, although, I think that any immediate solution
would be somewhat hacky.  I think that shared slots should not be
EFFECTIVE as used in the AMOP terminology, seems like another kind of
slot definition metaobject is needed in the metaobject pantheon.


> 
> >   This one may not have an answer:
> >   What makes an instance an instance?
> 
> It is pretty much a definition.
> 

what I really meant is:  if I write a primary on allocate-instance and
say,
allocate an array as the instance, then how do I get the generic
functions
to understand that my object *is a* some class.

> > c) In SLOT-VALUE-USING-CLASS, what is the CLASS?  Is the class
> >    where the slot is defined or is it (SLOT-DEFINITION-CLASS <sd>)?
> 
> The class in which the slot was defined.  The intent is to allow you to
> special this method so that slot access will be handled in a different
> way for particular classes.  This often incurs sometimes pretty stiff
> performance penalties.

Consider this:

(defclass super () (x) (:metaclass m1))
(defclass sub (super) () (:metaclass m2))

where m2 specializes m1.  Now, X is really not defined in SUB, so should
I call:

(slot-value-using-class (find-class 'super) ....)
(slot-value-using-class (find-class 'sub) ...)

both of which may give drastically different results.

I'm not particualrly worried about the penalties, I think that once the
techniques and problems are understood, the performance issues can (for
the most part)
be compiled away.

Thanks,
Tunc

> 
> --
> Thomas A. Russ,  USC/Information Sciences Institute          ···@isi.edu
From: Barry Margolin
Subject: Re: [CLOS/MOP] Allocation and access
Date: 
Message-ID: <27P65.48$db4.1048@burlma1-snr2>
In article <·················@robotics.eecs.berkeley.edu>,
Tunc Simsek  <······@robotics.eecs.berkeley.edu> wrote:
>what I really meant is:  if I write a primary on allocate-instance and
>say,
>allocate an array as the instance, then how do I get the generic
>functions
>to understand that my object *is a* some class.

I don't have AMOP handy, but I think there's supposed to be a MOP function
you call to create an instance object.  Or maybe you're not supposed to
replace the primary method, you should only write before/after/around
methods, or use CALL-NEXT-METHOD, to ensure that the system's primary
method gets called to actually create the instance.

>> > c) In SLOT-VALUE-USING-CLASS, what is the CLASS?  Is the class
>> >    where the slot is defined or is it (SLOT-DEFINITION-CLASS <sd>)?
>> 
>> The class in which the slot was defined.  The intent is to allow you to
>> special this method so that slot access will be handled in a different
>> way for particular classes.  This often incurs sometimes pretty stiff
>> performance penalties.
>
>Consider this:
>
>(defclass super () (x) (:metaclass m1))
>(defclass sub (super) () (:metaclass m2))
>
>where m2 specializes m1.  Now, X is really not defined in SUB, so should
>I call:
>
>(slot-value-using-class (find-class 'super) ....)
>(slot-value-using-class (find-class 'sub) ...)
>
>both of which may give drastically different results.

I believe the system-supplied implementation of:

(slot-value object slot)

is supposed to call:

(slot-value-using-class (class-of object) object slot)

So it will be the subclass that's used as the argument.  If M2 is a
subclass of M1, which is what I think you meant by "m2 specializes m1" then
M2's SLOT-VALUE-USING-CLASS method should be able to fall through to M1's
in order to access the X slot.

-- 
Barry Margolin, ······@genuity.net
Genuity, 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: Tunc Simsek
Subject: Re: [CLOS/MOP] Allocation and access
Date: 
Message-ID: <395BDB91.3F352CA7@robotics.eecs.berkeley.edu>
Barry Margolin wrote:
> 
> In article <·················@robotics.eecs.berkeley.edu>,
> Tunc Simsek  <······@robotics.eecs.berkeley.edu> wrote:
> >what I really meant is:  if I write a primary on allocate-instance and
> >say,
> >allocate an array as the instance, then how do I get the generic
> >functions
> >to understand that my object *is a* some class.
> 
> I don't have AMOP handy, but I think there's supposed to be a MOP function
> you call to create an instance object.  Or maybe you're not supposed to
> replace the primary method, you should only write before/after/around
> methods, or use CALL-NEXT-METHOD, to ensure that the system's primary
> method gets called to actually create the instance.
> 

In principle, yes, you should use ALLOCATE-INSTANCE with after methods
etc ...
But in my case, I really need to define a primary (allocating minimal
space for types, aligning slots with superclasses etc. that cannot
be done with after methods.)

It seems that the protocol should go a little lower level.

> >> > c) In SLOT-VALUE-USING-CLASS, what is the CLASS?  Is the class
> >> >    where the slot is defined or is it (SLOT-DEFINITION-CLASS <sd>)?
> >>
> >> The class in which the slot was defined.  The intent is to allow you to
> >> special this method so that slot access will be handled in a different
> >> way for particular classes.  This often incurs sometimes pretty stiff
> >> performance penalties.
> >
> >Consider this:
> >
> >(defclass super () (x) (:metaclass m1))
> >(defclass sub (super) () (:metaclass m2))
> >
> >where m2 specializes m1.  Now, X is really not defined in SUB, so should
> >I call:
> >
> >(slot-value-using-class (find-class 'super) ....)
> >(slot-value-using-class (find-class 'sub) ...)
> >
> >both of which may give drastically different results.
> 
> I believe the system-supplied implementation of:
> 
> (slot-value object slot)
> 
> is supposed to call:
> 
> (slot-value-using-class (class-of object) object slot)
> 
> So it will be the subclass that's used as the argument.  If M2 is a
> subclass of M1, which is what I think you meant by "m2 specializes m1" then
> M2's SLOT-VALUE-USING-CLASS method should be able to fall through to M1's
> in order to access the X slot.

hmm, that's weird, and hard to see the real purpose.
Anyway, I'll think about it.

Thanks,
Tunc
> 
> --
> Barry Margolin, ······@genuity.net
> Genuity, 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: Barry Margolin
Subject: Re: [CLOS/MOP] Allocation and access
Date: 
Message-ID: <7fR65.60$db4.1114@burlma1-snr2>
In article <·················@robotics.eecs.berkeley.edu>,
Tunc Simsek  <······@robotics.eecs.berkeley.edu> wrote:
>Barry Margolin wrote:
>> I believe the system-supplied implementation of:
>> 
>> (slot-value object slot)
>> 
>> is supposed to call:
>> 
>> (slot-value-using-class (class-of object) object slot)
>> 
>> So it will be the subclass that's used as the argument.  If M2 is a
>> subclass of M1, which is what I think you meant by "m2 specializes m1" then
>> M2's SLOT-VALUE-USING-CLASS method should be able to fall through to M1's
>> in order to access the X slot.
>
>hmm, that's weird, and hard to see the real purpose.
>Anyway, I'll think about it.

How else would the metaclass get to intercede in the slot-value protocol if
it didn't call a method that accepted the class as an argument, in order
for it to be specialized on the metaclass?

-- 
Barry Margolin, ······@genuity.net
Genuity, 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: Tunc Simsek
Subject: Re: [CLOS/MOP] Allocation and access
Date: 
Message-ID: <395BE3B1.9D8DCFC8@robotics.eecs.berkeley.edu>
Barry Margolin wrote:
> 
> In article <·················@robotics.eecs.berkeley.edu>,
> Tunc Simsek  <······@robotics.eecs.berkeley.edu> wrote:
> >Barry Margolin wrote:
> >> I believe the system-supplied implementation of:
> >>
> >> (slot-value object slot)
> >>
> >> is supposed to call:
> >>
> >> (slot-value-using-class (class-of object) object slot)
> >>
> >> So it will be the subclass that's used as the argument.  If M2 is a
> >> subclass of M1, which is what I think you meant by "m2 specializes m1" then
> >> M2's SLOT-VALUE-USING-CLASS method should be able to fall through to M1's
> >> in order to access the X slot.
> >
> >hmm, that's weird, and hard to see the real purpose.
> >Anyway, I'll think about it.
> 
> How else would the metaclass get to intercede in the slot-value protocol if
> it didn't call a method that accepted the class as an argument, in order
> for it to be specialized on the metaclass?
> 

sorry, what is weird is that the class is (class-of object) and not the
particular class for which slot was defined (it may have been
inherited).
I guess that the additional richness of the metaobjects may become 
unstable if these concepts are not used well.


> --
> Barry Margolin, ······@genuity.net
> Genuity, 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: Barry Margolin
Subject: Re: [CLOS/MOP] Allocation and access
Date: 
Message-ID: <6H875.77$db4.2170@burlma1-snr2>
In article <·················@robotics.eecs.berkeley.edu>,
Tunc Simsek  <······@robotics.eecs.berkeley.edu> wrote:
>sorry, what is weird is that the class is (class-of object) and not the
>particular class for which slot was defined (it may have been
>inherited).
>I guess that the additional richness of the metaobjects may become 
>unstable if these concepts are not used well.

It's the metaclass's job to figure out in which class the slot was defined.
A metaclass could even implement virtual slots that aren't defined in any
class at all.  It's the job of SLOT-VALUE-USING-CLASS to sort all this out,
and at the time it's called all you have is the object and the slot name.
You can determine the class of the object from the object, but without
calling some metafunction you can't get the class that defined the slot.

Like I said, I don't have AMOP handy, so I could be misremembering this.
I'll bet it describes this protocol clearly.

-- 
Barry Margolin, ······@genuity.net
Genuity, 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.