[cells] don't evaluate drifter on make-instance
Posted: Thu Feb 25, 2010 12:11 pm
i have an ephemeral cell which is NIL and a drifter cell which depends on the ephemeral cell. my problem is that the body of the drift cell
gets evaluated when the class is instantiated. thus i always have to check the ephemeral against NIL. is there a way to avoid evaluating the drift body on class instantiation? the drift cell has a initial value anyway...
in my real application the ephemeral cell is from another class and is probably NIL when the drifter is instantiated so i cannot set it to something "useful" :/
i also tried to make the ephemeral cell lazy but it is asked as soon as the drifter cell is initialized.
gets evaluated when the class is instantiated. thus i always have to check the ephemeral against NIL. is there a way to avoid evaluating the drift body on class instantiation? the drift cell has a initial value anyway...
Code: Select all
(cells-reset)
(defmodel drifter ()
((drift :cell :ephemeral :initform (c-formula (:inputp T :lazy :until-asked) (break "asked") NIL) :accessor drift-of)
(val :initarg :val :accessor val-of))
(:default-initargs ; if you remove this whole block then (break "asked") won't be called
:val (c... (50)
(if (null (^drift-of)) ; how do avoid this???
(progn (format T "~&initial drift?") 1)
(let ((d (- 50 (random (^drift-of)))))
(format T "~&drift: ~S" d)
d)))))
(defparameter drifter1 (make-instance 'drifter))
(val-of drifter1)
(setf (drift-of drifter1) 100)
(val-of drifter1)
i also tried to make the ephemeral cell lazy but it is asked as soon as the drifter cell is initialized.