[cells-devel] How does cells deal with in-place modification of slot values?

Ken Tilton kennytilton at optonline.net
Sun May 18 20:31:27 UTC 2008


Larry Clapp wrote:
> 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.

Ah, now it is really tough. If it was my code accessing my internal 
structure I would Just Create the Glue to drive the Cells engine (eg. 
Peter Hildebrandt is playing with some glue to make hash tables Cellsy), 
but if some else is mutating an object /and not telling me/ I am stuck 
unless I can find some way to hook into that process.

Cells is more about me making /my/ model work automatically and also 
does well working with external libs with callback schemes or something 
like Tcl/Tk does something similar linking state but also gives me a 
hook so I can propagate into Cells-land. But if you have an external 
library mutating state you care about but there is no way normally for 
you to know... well, what would you do anyway? Poll the state? If so, 
that is where I would put a hook to feed the Cells beast with dataflow.

Beating a dead horse: When dealing with OS events, it gives me an event 
and that is it, it does not change that event afterwards in ways that 
would matter to me, for obvious reasons.

hth, kenny

> 
> "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
> 
> _______________________________________________
> cells-devel site list
> cells-devel at common-lisp.net
> http://common-lisp.net/mailman/listinfo/cells-devel
> 




More information about the cells-devel mailing list