Re: intercepting (setf accessor)
- From: Ken Tilton <kentilton@xxxxxxxxx>
- Date: Sun, 19 Mar 2006 02:35:27 -0500
Sacha wrote:
Let's say i have a class defined as follow :
(defclass item ()
((parent :accessor parent)))
What i want is a way to intercept calls to (setf (parent item-instance) parent-object)
(defmethod (setf parent) :around (new-value (self item))
(if <everything is cool>
(call-next-method)
(break "what on earth are you thinking about?")))
other ways to augment are :before and :after where you see :around, but :around let's you play with new-value or see the result of the normal method (not to shocking in this case since we all know what setf does, but I am talking about GFs in general.
Find something somewhere on :before, :after, :around, and (call-next-method) and learn those. Pretty simple, very necessary.
I thought this was only for "more specialized" methods, good to know i can do it like this.
But really that's not what i want to do.
Let's take a precise example.
I have this item object which could in an index or not.
I want to be able to define my index without the item class knowning about it.
No reference to the index in the "item" class.
When the item is added to my index, the index should be warned about changes to the indexed fields.
That's at this point that i want the index to "register" for item "slot change events".
When the item is removed, the index should not be warned anymore. So there should be some kind of "unregistering".
The index object should be generic in the sense that i don't want to have a subclass of it
for every classes that will one day or another be indexed
Also i'm not sure an EQL specialiser could be created on every insert.
And not sure either that this would be the good thing to do.
And not sure how to do this anyways =P
You may be thinking in C++. There t he interceptor method would have to be built into the class. That is not CLOS. In CLOS, once a class is defined, any other subsystem can specialize methods on that class, without any cooperation from that class.
kt
.
- References:
- intercepting (setf accessor)
- From: Sacha
- Re: intercepting (setf accessor)
- From: Ken Tilton
- Re: intercepting (setf accessor)
- From: Sacha
- intercepting (setf accessor)
- Prev by Date: Re: intercepting (setf accessor)
- Next by Date: Re: intercepting (setf accessor)
- Previous by thread: Re: intercepting (setf accessor)
- Next by thread: Re: intercepting (setf accessor)
- Index(es):
Relevant Pages
|