As promised yesterday I added a cells-store facility to cells. The
code can be found at the bottom of md-utilities in CVS.
Basically, this is a cells-aware hash table with some syntactic sugar.
Here's part of the test function included in md-utilities:
(defun test-cells-store ()
(trc "testing cells-store -- making objects")
(let* ((store (make-instance 'cells-store))
(foo (make-instance 'test-store-item :value (c?-with-stored (v :foo
store 'nothing)
(bwhen (val (value v)) val))))
(foo+1 (make-instance 'test-store-item :value (c?-with-stored (v
:foo store 'nothing)
(bwhen (val (value v)) (1+ val))))))
(store-add :foo store (make-instance 'family :value (c-in nil)))
(setf (value (store-lookup :foo store)) 1)
(store-remove :foo store))
So you create a ruled cell with c?-with-stored. This can happen
before or after key is added to the cells-store. When the rule is the
executed, when an object is added or removed from key in the hash
table *or* when any of the cells on the object change. The rule is
not executed, if other stuff in the hash table changes.
The (c?-with-stored (var key store &optional default) &body body)
macro works like bwhen -- that is, if key is present, body is executed
with var bound to the object identified by key -- and if not, default
is returned. That means, body can assume that var is bound to a valid
object (like in the example, it is safe to call value on it, if you
know that you only store family instances in the store)
Calling store-remove will reset all dependent cells to their default.
The change is propagated as soon as store-add, setf, or store-remove
are called -- meaning that observers will do the expected thing.
Maybe someone will find it useful.
Peter