Re: CLOS Question - Making an object a constant



Thanks for your reply...

I have been really meaning to read up on the MOP for quite some time
now. Do you have any good references that you would recommend?

Thanks once again...

Regards,
Sachin.


You could trap it with something like this:

(asdf:oos 'asdf:load-op :closer-mop)

(defmethod closer-mop:slot-makunbound-using-class :after
(class (object (eql *constant-object*)) slot-definition)
(declare (ignore class))
(when (eql 'constant-slot (closer-mop:slot-definition-name slot-definition))
(error "Made unbound the constant slot ~A of the constant object ~A"
'constant-slot object))
object)

(defmethod (setf closer-mop:slot-value-using-class) :after
(new-value class (object (eql *constant-object*)) slot-definition)
(when (eql 'constant-slot (closer-mop:slot-definition-name slot-definition))
(error "Assigned to the constant slot ~A of the constant object ~A"
'constant-slot object))
new-value)

.