Page 1 of 1
Capturing a change in slot value.
Posted: Sat May 31, 2014 6:13 pm
by macrolyte
Hey.
I've been pouring over the
Hyperspec and some other resources but haven't found a reasonable solution. Initially I played hide & seek with slot-boundp:
Code: Select all
defmethod initialize-instance :after ((node b-node) &key) ;; DON'T EVEN THINK ABOUT TRYING THIS!!!!!
(loop while (slot-boundp node 'stat) do ;; test to see if a change in slot value would trigger an unbound condition, (non working code...)
(print "started"))
(funcall (lambda()(print "done"))))
Please
don't use the code above. I've looked at
make-load-form-saving-slots as well but I would have to poll a parsed version of the value it returns which is just, ugh. My last option is to create an additional slot which I can use as a wayback machine... Thanks in advance.
Re: Capturing a change in slot value.
Posted: Sun Jun 01, 2014 5:28 am
by pjstirling
I'm not entirely sure what you want to do here, do you want to:
- check if the instance is created using the default value for a slot
- fire some code when the slot is given a value the first/every time
Re: Capturing a change in slot value.
Posted: Sun Jun 01, 2014 10:07 am
by macrolyte
pjstirling wrote:I'm not entirely sure what you want to do here, do you want to:
- check if the instance is created using the default value for a slot
- fire some code when the slot is given a value the first/every time
Sorry about being
unclear, the "fire some code ..." is what I'm trying to do. I just realized that a function object can be a slot value so I've been trying to piece this together from that direction. Thanks!
Re: Capturing a change in slot value.
Posted: Sun Jun 01, 2014 10:32 am
by Goheeca
I don't know at which level do you want the capturing. That's my solution:
Code: Select all
(defclass foo ()
((bar :accessor bar-acc)))
(defmethod (setf bar-acc) :before (new-value (instance foo))
(format t "~&Hey, you are setfing bar in this baz (~a) to ~a.~%" instance new-value))
and usage
Code: Select all
(defvar *obj* (make-instance 'foo))
(setf (bar-acc *obj*) t)
Just for higher meta level use MOP.
Re: Capturing a change in slot value.
Posted: Sun Jun 01, 2014 11:22 am
by macrolyte
I need to read the Hyperspec, give me a few minutes. (It works BTW...). Thanks!
Re: Capturing a change in slot value.
Posted: Sun Jun 01, 2014 11:52 am
by macrolyte
Goheeca wrote:
Code: Select all
(defmethod (setf bar-acc) :before (new-value (instance foo)) ;; <===== see below
(format t "~&Hey, you are setfing bar in this baz (~a) to ~a.~%" instance new-value))
Is this about the specialize lambda list with parameters matching types/objects thing? And where the @$%^ is the method name?
Goheeca wrote:
Just for higher meta level use MOP.
Huh?
Re: Capturing a change in slot value.
Posted: Sun Jun 01, 2014 12:50 pm
by Goheeca
Yes it is. The method name is
bar-acc, the notation is for getter:
and for setter:
MOP is API for the object metaprogramming, the wrapping library negotiating implementation-dependent details is
closer-mop.
Re: Capturing a change in slot value.
Posted: Sun Jun 01, 2014 3:09 pm
by macrolyte
Thanks again, Goheeca. At least you've given me a starting point, so I'll get back to work now. Pax vobiscum.