[resolved] access old value in cells

Discussion of Common Lisp

[resolved] access old value in cells

Postby hewih » Sun Jan 31, 2010 8:44 am

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.
Last edited by hewih on Sun Jan 31, 2010 11:15 am, edited 2 times in total.
User avatar
hewih
 
Posts: 30
Joined: Tue Jan 19, 2010 9:36 am

Re: access old value in cells

Postby Ramarren » Sun Jan 31, 2010 9:17 am

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.
Ramarren
 
Posts: 613
Joined: Sun Jun 29, 2008 4:02 am
Location: Warsaw, Poland

Re: access old value in cells

Postby hewih » Sun Jan 31, 2010 11:13 am

thx! ^^
User avatar
hewih
 
Posts: 30
Joined: Tue Jan 19, 2010 9:36 am


Return to Common Lisp

Who is online

Users browsing this forum: No registered users and 1 guest