This is a read-only archive of lispforum.com. The forum was locked to new users and posts and is preserved here as static HTML from a database snapshot taken on 2019-09-07.

[resolved] access old value in cells

3 posts · 1415 views

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.
(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.

Last edited by hewih on , edited 2 times in total.

Re: access old value in cells

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

thx! ^^