[cells-devel] A question about the use of vectors in CELLS
Peder Chr. Nørgaard
pcn at pogt.dk
Mon May 18 15:48:44 UTC 2009
Larry, thanks for the answer. Yes, a trick (OK, a technique) like this would
probably do the job for me. I was kind of leaning in the same direction
myself, Kenneth Tilton's response pointing to Peter
Hildebrandt's "cells-store" extension which is actually a part of the Cells
package that I am using and using more or less the same hack (OK, same
technique) :-).
So, everybody, thanks for your help, Kenneth, Jakub, Larry. And Peter
Hildebrandt, I found the Aug 2008 mail describing the rationale for
cells-store (not to be churlish, but that text ought to be in cells source
code package, not in a mail somewhere. It is valuable!).
I have the answer to my problem now. Just have to decide what to do.
best regards
--peder chr.
On Monday 18 May 2009, Larry Clapp wrote:
> On Sat, May 16, 2009 at 04:23:41PM +0200, Peder Chr. Nørgaard wrote:
> > I am attempting to use a vector as the value in a slot. It does not
> > work well in first attempt:
> >
> > CL-USER> (use-package :cells)
> > T
> > CL-USER> (defparameter a1 (make-instance 'model :value (c-in #(1 2 3
> > 4)))) A1
> > CL-USER> (defparameter a2 (make-instance 'model :value (c? (apply #'+
> > (map 'list #'identity (value a1))))))
> > A2
> > CL-USER> (value a2)
> > 10
> > CL-USER> (setf (elt (value a1) 1) 5)
> > 5
> > CL-USER> (value a1)
> > #(1 5 3 4)
> > CL-USER> (value a2)
> > 10
> >
> > The VALUE slot of A2, depending on (VALUE A1) is not changing when
> > (VALUE A1) is, shall we call it "changed in place".
> >
> > The cells version is
> > from
> > :pserver:anonymous:anonymous at common-lisp.net:/project/cells/cvsroot.
> >
> > The Lisp system is SBCL is 1.0.18.0-2.
> >
> > I would like to enquire whether I am simply doing something
> > trivially wrong, or whether this is something that simply cannot be
> > done without a major CELLS extension for support of vector values
> > (like, FAMILY, can be viewed as a kind of support for list values).
> > The latter answer may force me to reconsider an implementation that
> > I had in mind.
>
> I asked a similar question almost exactly a year ago. Hmmm. :)
> Anyway, see
> http://common-lisp.net/pipermail/cells-devel/2008-May/002035.html .
> The general answer hasn't changed since then: either don't do that, or
> recons the sequence, or make the cell formula depend on something else
> that changes directly in addition to the stuff it actually depends on.
> (In last year's thread, Peter Hildebrandt noted that this last option
> is how cells-store works.)
>
> I played with the last option a bit today, and came up with this
> (which may or may not work very well in real usage, but the toy
> example below works):
>
> (defmodel change-counter ()
> ((count :initform (c-in 0) :accessor count-of)))
>
> (defmethod kick ((self change-counter))
> (incf (count-of self)))
>
> (defmacro change-watcher ((model) &body body)
> `(progn
> (count-of ,model)
> , at body))
>
> (defmacro with-changes ((&rest models) &body body)
> `(unwind-protect
> (progn , at body)
> (with-integrity (:change)
> (dolist (model (list , at models))
> (kick model)))))
>
> Example (Lispworks, if it matters):
>
> CELLS-PLAY 217 > (defmodel test (change-counter)
> ((slot :initarg :slot :accessor slot-of)))
> NIL
>
> CELLS-PLAY 218 > (defparameter a1 (make-instance 'test :slot (c-in #(1 2
> 3 4)))) A1
>
> CELLS-PLAY 219 > (defparameter a2 (make-instance 'test :slot (c?
> (change-watcher (a1)
> (format t "recalc a2's s~%")
> (apply '+ (coerce (slot-of a1) 'list))))))
> recalc a2's s
> A2
>
> CELLS-PLAY 220 > (slot-of a2)
> 10
>
> CELLS-PLAY 221 > (with-changes (a1)
> (setf (aref (slot-of a1) 1) 5))
> recalc a2's s
> 5
>
> CELLS-PLAY 222 > (slot-of a2)
> 13
>
> CELLS-PLAY 223 > (slot-of a1)
> #(1 5 3 4)
>
> Hope that's helpful.
>
> -- Larry
--
Peder Chr. Nørgaard e-mail: pcn at pogt.dk
Gefionsvej 19
DK-8230 Åbyhøj tel: +45 87 44 11 99
Denmark mob: +45 30 91 84 31
More information about the cells-devel
mailing list