Hi,
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.
Thanks for any help.
Regards,
Sachin.
From: Pascal Costanza
Subject: Re: CLOS Question - Making an object a constant
Date:
Message-ID: <4gg9glF1n1ffiU1@individual.net>
skamboj wrote:
> Hi,
>
> 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.
Can you give us the class definition?
Do you specify :accessor for any of the slots? If so, replace this with
:reader - :accessor also implicitly creates a :writer function.
Do you call any of the initialization functions (initialize-instance,
reinitialize-instance, shared-initialize, update-instance-xyz)? If so, why?
Do you use (setf (slot-value ...) ...) anywhere in your code? If so, try
to avoid that, but better use accessor functions instead (as generated
by :accessor, :reader or :writer).
If it is too much work to change calls to slot-value, try this: Instead
of giving the slots in the respective class "proper" names, use
generated symbols instead. Like this:
(defclass some-class ()
((#.(gensym) :initarg :bla :reader bla)))
Then a slot-value function won't be able to access such a slot. (But be
careful, this is quite gross and better be used only for debugging.)
There are more fine-grained ways to find the problem, but maybe this
already helps.
Pascal
--
3rd European Lisp Workshop
July 3 - Nantes, France - co-located with ECOOP 2006
http://lisp-ecoop06.bknr.net/
First of all thanks for replying...
With further debugging, I was able to resolve the problem.
The problem was that the slot value was a list which was apparantly
loosing one of its elements. I traced the problem to calling the sort
function and I had forgotten that it destructively modifies the list.
The slot was not being directly written to, hence changing the
:accessor to a :reader didn't help. However, that was an excellant
suggestion.
Thanks to all those who replied.
Regards,
Sachin.
On Wed, 28 Jun 2006 23:09:38 +0200, Pascal Costanza <··@p-cos.net> wrote:
>
> If it is too much work to change calls to slot-value, try this: Instead
> of giving the slots in the respective class "proper" names, use
> generated symbols instead. Like this:
>
> (defclass some-class ()
> ((#.(gensym) :initarg :bla :reader bla)))
>
> Then a slot-value function won't be able to access such a slot. (But be
> careful, this is quite gross and better be used only for debugging.)
>
Thanks Costanza. That is beutiful!
--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
"skamboj" <·······@gmail.com> 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------
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)
From: Pascal Costanza
Subject: Re: CLOS Question - Making an object a constant
Date:
Message-ID: <4giikgF1mosugU1@individual.net>
skamboj wrote:
> 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?
There are two good resources:
- Andreas Paepcke, User-Level Language Crafting - it's a paper free for
download, google for it
- Gregor Kiczales, Jim des Rivieres, Daniel Bobrow, The Art of the
Metaobject Protocol. It's a book, not free, but a must-read.
Pascal
--
3rd European Lisp Workshop
July 3 - Nantes, France - co-located with ECOOP 2006
http://lisp-ecoop06.bknr.net/
skamboj wrote:
> Hi,
>
> 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.
>
> Thanks for any help.
>
> Regards,
> Sachin.
>
You don't use slot-value, right. Then just specify a :reader instead of
an :accessor for that very slot. Ok, you've got to use slot-value in the
initialization code then .. hmm ... who knows better ways?
> You don't use slot-value, right. Then just specify a :reader instead of
> an :accessor for that very slot. Ok, you've got to use slot-value in the
> initialization code then .. hmm ... who knows better ways?
Sorry folks, .. should update the news-reader display more frequently
... forget my answer.