[cells-devel] How does cells deal with in-place modification of slot values?
Larry Clapp
larry at theclapp.org
Sun May 18 20:17:52 UTC 2008
See subject.
In other words, say I have a class with two slots, a and b, with b
sort-of dependant on a:
(defmodel test ()
((a :initarg :a :initform (c-in (list 'a)) :accessor a)
(b :initarg :b :initform (c? (car (^a))) :accessor b)))
(defmethod print-object ((self test) stream)
(print-unreadable-object (self stream :type t :identity t)
(format stream "a: ~S, b: ~S" (^a) (^b))))
(setf *a* (make-instance 'test))
CELLS 11 > *a*
#<TEST a: (A), b: A 22ED4D93>
CELLS 12 > (setf (car (a *a*)) 'd)
D
CELLS 13 > *a*
#<TEST a: (D), b: A 22ED4D93>
Slots a and b are now out of sync. What's the ideo-cells-ic way to do
this?
What I'm really trying to do is wrap a class around somebody else's
object. The internal state of the object changes, and I'd like to
figure out some way to make the Cells system aware of the change.
"Native" use of the object is something like this
(some-other-package:perturb-test self)
Do I need to wrap perturb-test too? e.g.
(defmodel test ()
((a :initarg :a :initform (c-in (list 'a)) :accessor a)
(a-changed :initform (c-in 0) :accessor a-changed)
(b :initarg :b :initform (c? (and (^a-changed) (car (^a)))) :accessor b)))
(defmethod print-object ((self test) stream)
(print-unreadable-object (self stream :type t :identity t)
(format stream "a: ~S, b: ~S" (^a) (^b))))
(setf *a* (make-instance 'test))
(defun perturb-test (self y)
(prog1
(setf (car (^a)) y)
(incf (^a-changed))))
CELLS 34 > *a*
#<TEST a: (D), b: D 200A742F>
CELLS 35 > (perturb-test *a* 'e)
E
CELLS 36 > *a*
#<TEST a: (E), b: E 200A742F>
-- Larry
More information about the cells-devel
mailing list