Lisp HUG Maillist Archive

make-instance does not call slot-value-using-class?

Hi,

I have problems with Lispworks MOP behavior.

| CL-USER 1 > (defclass foo () ((x :initarg :x)))
| #<STANDARD-CLASS FOO 402016A5FB>
| 
| CL-USER 2 > (trace (setf clos:slot-value-using-class))
| ((SETF CLOS:SLOT-VALUE-USING-CLASS))
| 
| CL-USER 3 > (make-instance 'foo :x 2)
| #<FOO 402005052B>

Why in this case, SLOT-VALUE-USING-CLASS be not called?
(I found :optimize-slot-access keyword from the mail archive,
but it seems have no effect.)

If I call SLOT-VALUE explicitly like below, it looks ok.

| CL-USER 4 > (setf (slot-value * 'x) 3)
| 0 (SETF CLOS:SLOT-VALUE-USING-CLASS) > ...
|   >> CLOS::NEW-VALUE : 3
|   >> CLASS           : #<STANDARD-CLASS FOO 41500E14A3>
|   >> CLOS::OBJECT    : #<FOO 402005052B>
|   >> CLOS::SLOT-NAME : X
| 0 (SETF CLOS:SLOT-VALUE-USING-CLASS) < ...
|   << VALUE-0 : 3
| 3

But here's another problem.
My understandig says the fourth argument to S-V-U-C should be
STANDARD-EFFECTIVE-SLOT-DEFINITION not symbol X, in this case?

_______________________________________________
Lisp Hug - the mailing list for LispWorks users
lisp-hug@lispworks.com
http://www.lispworks.com/support/lisp-hug.html


Re: make-instance does not call slot-value-using-class?

Hi,

1) It is valid for a CLOS implementation not to call (setf slot-value-using-class) during initialization. If you need extra behavior during initialization, you need to define :after methods on initialize-instance. (A metaclass can add mixin classes to ensure that there are such :after methods.)

2) LispWorks indeed passes a symbol, not a metaobject, as the third argument, and is not conforming in that regard. If you develop only for LispWorks, this shouldn't be a big problem. For portable code, check out Closer to MOP, which makes LispWorks mire conforming...

Pascal

Sent from my iPad

> On 24 Mar 2014, at 08:55, KURODA Hisao <kuroda@msi.co.jp> wrote:
> 
> 
> Hi,
> 
> I have problems with Lispworks MOP behavior.
> 
> | CL-USER 1 > (defclass foo () ((x :initarg :x)))
> | #<STANDARD-CLASS FOO 402016A5FB>
> | 
> | CL-USER 2 > (trace (setf clos:slot-value-using-class))
> | ((SETF CLOS:SLOT-VALUE-USING-CLASS))
> | 
> | CL-USER 3 > (make-instance 'foo :x 2)
> | #<FOO 402005052B>
> 
> Why in this case, SLOT-VALUE-USING-CLASS be not called?
> (I found :optimize-slot-access keyword from the mail archive,
> but it seems have no effect.)
> 
> If I call SLOT-VALUE explicitly like below, it looks ok.
> 
> | CL-USER 4 > (setf (slot-value * 'x) 3)
> | 0 (SETF CLOS:SLOT-VALUE-USING-CLASS) > ...
> |   >> CLOS::NEW-VALUE : 3
> |   >> CLASS           : #<STANDARD-CLASS FOO 41500E14A3>
> |   >> CLOS::OBJECT    : #<FOO 402005052B>
> |   >> CLOS::SLOT-NAME : X
> | 0 (SETF CLOS:SLOT-VALUE-USING-CLASS) < ...
> |   << VALUE-0 : 3
> | 3
> 
> But here's another problem.
> My understandig says the fourth argument to S-V-U-C should be
> STANDARD-EFFECTIVE-SLOT-DEFINITION not symbol X, in this case?
> 
> _______________________________________________
> Lisp Hug - the mailing list for LispWorks users
> lisp-hug@lispworks.com
> http://www.lispworks.com/support/lisp-hug.html
> 

_______________________________________________
Lisp Hug - the mailing list for LispWorks users
lisp-hug@lispworks.com
http://www.lispworks.com/support/lisp-hug.html


Re: make-instance does not call slot-value-using-class?

Hallo,

Pascal Costanza <pc@p-cos.net> writes:

> 1) It is valid for a CLOS implementation not to call (setf slot-value-using-class) during initialization. If you need extra behavior during initialization, you need to define :after methods on initialize-instance. (A metaclass can add mixin classes to ensure that there are such :after methods.)

Thanks for the tips.  I'll try.

> 2) LispWorks indeed passes a symbol, not a metaobject, as the third argument, and is not conforming in that regard. If you develop only for LispWorks, this shouldn't be a big problem. For portable code, check out Closer to MOP, which makes LispWorks mire conforming...

O.K.  I've already written the workaround in this case.  But the code
looks ugly...  Anyway, I will study "Closer to MOP".  Thanks again.

>
> Pascal
>
> Sent from my iPad
>
>> On 24 Mar 2014, at 08:55, KURODA Hisao <kuroda@msi.co.jp> wrote:
>> 
>> 
>> Hi,
>> 
>> I have problems with Lispworks MOP behavior.
>> 
>> | CL-USER 1 > (defclass foo () ((x :initarg :x)))
>> | #<STANDARD-CLASS FOO 402016A5FB>
>> | 
>> | CL-USER 2 > (trace (setf clos:slot-value-using-class))
>> | ((SETF CLOS:SLOT-VALUE-USING-CLASS))
>> | 
>> | CL-USER 3 > (make-instance 'foo :x 2)
>> | #<FOO 402005052B>
>> 
>> Why in this case, SLOT-VALUE-USING-CLASS be not called?
>> (I found :optimize-slot-access keyword from the mail archive,
>> but it seems have no effect.)
>> 
>> If I call SLOT-VALUE explicitly like below, it looks ok.
>> 
>> | CL-USER 4 > (setf (slot-value * 'x) 3)
>> | 0 (SETF CLOS:SLOT-VALUE-USING-CLASS) > ...
>> |   >> CLOS::NEW-VALUE : 3
>> |   >> CLASS           : #<STANDARD-CLASS FOO 41500E14A3>
>> |   >> CLOS::OBJECT    : #<FOO 402005052B>
>> |   >> CLOS::SLOT-NAME : X
>> | 0 (SETF CLOS:SLOT-VALUE-USING-CLASS) < ...
>> |   << VALUE-0 : 3
>> | 3
>> 
>> But here's another problem.
>> My understandig says the fourth argument to S-V-U-C should be
>> STANDARD-EFFECTIVE-SLOT-DEFINITION not symbol X, in this case?
>> 
>> _______________________________________________
>> Lisp Hug - the mailing list for LispWorks users
>> lisp-hug@lispworks.com
>> http://www.lispworks.com/support/lisp-hug.html
>> 

_______________________________________________
Lisp Hug - the mailing list for LispWorks users
lisp-hug@lispworks.com
http://www.lispworks.com/support/lisp-hug.html


Updated at: 2020-12-10 08:34 UTC