Page 1 of 1

[resolved] access old value in cells

Posted: Sun Jan 31, 2010 8:44 am
by hewih
i have a rule evaluated cell which should only change it's value in certain cases and in some it should just stay the same.

Code: Select all

(in-package :cells)
(cells-reset)

(defmodel test ()
	((cell1 :initarg :cell1 :accessor cell1-of)
	 (eph1 :cell :ephemeral :initform (c-in NIL) :accessor eph1-of)
	 ))
	 
(defparameter test1
  (make-instance 'test
     :cell1 (c? (ecase (eph1-of self)
	               ((NIL) 0)
	               ('POS  1)
	               ('NEG -1)
	               ('NOTHING (^cell1-of)))))) ; access old-value here
				   
(setf (eph1-of test1) 'POS)
(format T "~&~S" (cell1-of test1))
(setf (eph1-of test1) 'NOTHING) ; c-dependency error
(format T "~&~S" (cell1-of test1))
(setf (eph1-of test1) 'NEG)
(format T "~&~S" (cell1-of test1))
(setf (eph1-of test1) 'NOTHING) ; c-dependency error
(format T "~&~S" (cell1-of test1))
if i refer to the cell1 in it's own c? i get a dependency error of course. how can i do that, without using a old-value slot?
something else i thought of which might work is using drifters... however in my actual code cell1 is a class, so incf and decf don't work there.

Re: access old value in cells

Posted: Sun Jan 31, 2010 9:17 am
by ramarren
You can access the previous value of a cell with a .cache implicit variable. There is an example in cells-test/hello-world.lisp more or less the same as what you are trying to do. There are also synapses for more complicated cases, where you want the value to change, but not propagate further.

Re: access old value in cells

Posted: Sun Jan 31, 2010 11:13 am
by hewih
thx! ^^