Re: CLOS Question - Making an object a constant



"skamboj" <skamboj@xxxxxxxxx> writes:
I am looking for a way to make an instance of a class a constant. Is
there a simple way to do this? Failing which, is there a simple way to
detect all changes to a slot of an object?

The reason that I am asking is that I have a relatively small lisp
application (ten thousand lines of code or so) that is crashing because
of a bug that causes a slot of an object to be modified. That object is
supposed to be a constant once completely initialized. However, I can't
seem to find out the place or function that is changing that slot.

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)



--
__Pascal Bourguignon__ http://www.informatimago.com/
-----BEGIN GEEK CODE BLOCK-----
Version: 3.12
GCS d? s++:++ a+ C+++ UL++++ P--- L+++ E+++ W++ N+++ o-- K- w---
O- M++ V PS PE++ Y++ PGP t+ 5+ X++ R !tv b+++ DI++++ D++
G e+++ h+ r-- z?
------END GEEK CODE BLOCK------
.