On Wed, Mar 10, 2010 at 1:39 PM, Alessio Stalla alessiostalla@gmail.com wrote:
On Wed, Mar 10, 2010 at 8:32 PM, Blake McBride blake@mcbride.name wrote:
Here is how to do it in SBCL. cv? represent class variables. iv? represent instance variables. Both associated to the "class1" class.
(defclass meta-class1 (standard-class) (cv1 cv2 cv3) (:metaclass standard-class))
(defmethod sb-mop:validate-superclass ((class meta-class1) (superclass standard-class)) t)
(defclass class1 (standard-object) (iv1 iv2 iv3) (:metaclass meta-class1))
(setf (slot-value (find-class 'class1) 'cv2) 'hello)
(slot-value (find-class 'class1) 'cv2)
That's a different thing. (slot-value (make-instance 'class1) 'cv2) ==> missing slot, i.e. you're not defining class-allocated slots as specified by the CL standard. I'm not saying your approach is wrong, but probably it's not what the OP asked.
(slot-value (make-instance 'class1) 'cv2)
creates an instance. He wanted access to a true class variable, stored in the class (class1) that was accessible via a class reference. If that's what he wanted, that's exactly what my code does.
My example code does store cv? in class1, not the meta-class.
Blake McBride