Hi,
I define a class
(defclass f ()
((foo :allocation :class
:initform 'foo-slot
:accessor foo)
(bar :initform 'bar-slot
:accessor bar)))
If I edit :initform of the bar slot and then (SLIME) C-c C-k (slime-
compile-and-load-file), new instances of f will have the new value for
the bar slot. This does not happen with the foo slot. This is, I
believe, due to the timing of the execution of :initform - it is
evaluated once when the class is defined. Obviously, C-c C-k isn't
causing the class allocated slot initform to be (re) evaluated. I see
the same behaviour with LispWorks.
How do I force the re-evaluation of a class allocated initform in an
environment like SLIME or LispWorks?
Thanks
Chris
From: Ken Tilton
Subject: Re: editing value of class allocated slots (timing of class creation)
Date:
Message-ID: <tqDVh.592$ru1.91@newsfe12.lga>
caw wrote:
> Hi,
>
> I define a class
>
> (defclass f ()
> ((foo :allocation :class
> :initform 'foo-slot
> :accessor foo)
> (bar :initform 'bar-slot
> :accessor bar)))
>
> If I edit :initform of the bar slot and then (SLIME) C-c C-k (slime-
> compile-and-load-file), new instances of f will have the new value for
> the bar slot. This does not happen with the foo slot. This is, I
> believe, due to the timing of the execution of :initform - it is
> evaluated once when the class is defined. Obviously, C-c C-k isn't
> causing the class allocated slot initform to be (re) evaluated. I see
> the same behaviour with LispWorks.
>
> How do I force the re-evaluation of a class allocated initform in an
> environment like SLIME or LispWorks?
In-frickin-possible. Totally frustrating, too.
The rationale obviously is that an initform in a class-allocated context
means /when the class is created/, not an instance. Looked at another
way, if I have an existing class whose class-allocated slot has been
modified from its initform, do I really want to reset that slot when I
merely /modify/ the class? Well, sadly, yes, that is invariably what I
want, but all the Lisps I know work the other way, so on with my life I get.
I think the easiest way I found was to comment out the slot, compile,
uncomment and recompile. Something like that, not sure.
kzo
--
http://www.theoryyalgebra.com/
"Algebra is the metaphysics of arithmetic." - John Ray
"As long as algebra is taught in school,
there will be prayer in school." - Cokie Roberts
"Stand firm in your refusal to remain conscious during algebra."
- Fran Lebowitz
"I'm an algebra liar. I figure two good lies make a positive."
- Tim Allen
From: Pascal Costanza
Subject: Re: editing value of class allocated slots (timing of class creation)
Date:
Message-ID: <58ol72F2ahenmU1@mid.individual.net>
Ken Tilton wrote:
>
>
> caw wrote:
>> Hi,
>>
>> I define a class
>>
>> (defclass f ()
>> ((foo :allocation :class
>> :initform 'foo-slot
>> :accessor foo)
>> (bar :initform 'bar-slot
>> :accessor bar)))
>>
>> If I edit :initform of the bar slot and then (SLIME) C-c C-k (slime-
>> compile-and-load-file), new instances of f will have the new value for
>> the bar slot. This does not happen with the foo slot. This is, I
>> believe, due to the timing of the execution of :initform - it is
>> evaluated once when the class is defined. Obviously, C-c C-k isn't
>> causing the class allocated slot initform to be (re) evaluated. I see
>> the same behaviour with LispWorks.
>>
>> How do I force the re-evaluation of a class allocated initform in an
>> environment like SLIME or LispWorks?
>
> In-frickin-possible. Totally frustrating, too.
>
> The rationale obviously is that an initform in a class-allocated context
> means /when the class is created/, not an instance. Looked at another
> way, if I have an existing class whose class-allocated slot has been
> modified from its initform, do I really want to reset that slot when I
> merely /modify/ the class? Well, sadly, yes, that is invariably what I
> want, but all the Lisps I know work the other way, so on with my life I
> get.
This is actually specified in ANSI Common Lisp, it's not just
implementation-dependent. A good mental model is that shared slots
behave like defvar, not like defparameter.
I have a metaclass in ContextL which allows you to reinitialize shared
slots by saying roughly something like the following:
(defclass class f ()
((foo :allocation :class
:initform 'foo-slot
:accessor foo
:reinitialize t)))
Maybe this could be ripped out from ContextL and provided as a separate
mechanism. It's most probably also possible to implement this as a plain
macro.
Pascal
--
My website: http://p-cos.net
Common Lisp Document Repository: http://cdr.eurolisp.org
Closer to MOP & ContextL: http://common-lisp.net/project/closer/