On 25 Apr 2009, at 13:56, Makarov Alexey wrote:


I defined metaclass and add in it some slot.

CL-USER> (defclass test-metaclass (standard-class)
                    ((my-slot :initarg :my-slot :reader my-slot-of)))

CL-USER> (defmethod sb-mop:validate-superclass ((class test-metaclass)
                                                                                (superclass standard-class)) T)

CL-USER> (defclass test () ()
                   (:metaclass test-metaclass)
                   (:my-slot 'test))

Trying to get value of my-slot:

CL-USER> (my-slot-of (find-class 'test))

Why value of slot "my-slot" wrapped in list?

...because that is what the CLOS MOP specification says. See the section "The defclass Macro" in "Compile-file Processing of the User Interface Macros": "Any other class options become the value of keyword arguments with the same name. The value of the keyword argument is the tail of the class option. An error is signaled if any class option appears more than once in the defclass form."

So you get the tail of the class option, which is by definition a list.

Maybe value of (my-slot-of (find-class 'test)) probably 'TEST, not ('TEST), isn't it?

If you want that, you have to say this:

(defclass test () ()
   (:metaclass test-metaclass)
   (:my-slot . 'test))

[Note the dot in front of 'test!]

In my experience, it's better to define a thin user-macro on top of your own metaclasses, like define-xyz-macro, to hide such details so that users of your metaclass cannot get confused here.



Pascal Costanza, mailto:pc@p-cos.net, http://p-cos.net
Vrije Universiteit Brussel
Programming Technology Lab
Artificial Intelligence Lab
Pleinlaan 2, B-1050 Brussel, Belgium