How can I enforce slot's type in CLOS.
I know that (locally (declare (optimize safety))) (defclass foo () ((num :type number...
could be answer, but I think it's not portable enough. (only with SBCL, not CLISP 2.49)
Or, should I implement those things? (for check each slots following specified :type
s.)
- defmethod
:after (setf SLOT)
. - defmethod
:after initialize-instance
.
Is there any simpler way to do that?
And, is there any "MOP" or metaclass something for hook "slot-updates"?
Thanks.
EDIT: I think it's not the same question with CLOS: How to make a slot have an enforced type of vector of symbols?, because I need more informations about that "metaclass" or slot-value-with-class
things.
EDIT: I found closer-mop
provides preferrable, portable-way.
CL-USER> (nth 0 (closer-mop:class-slots (find-class 'foo-class)))
CL-USER> (closer-mop:slot-definition-type *)