[cells-devel] Added cells-store to cells

Ken Tilton kennytilton at optonline.net
Thu Apr 17 14:52:25 UTC 2008


Peter Hildebrandt wrote:
> As promised yesterday I added a cells-store facility to cells.   The
> code can be found at the bottom of md-utilities in CVS.

Cool. I am curious what application requirement led to this. Not that it 
is not a good idea. Being able to reach inside other structures for 
dependency is a natural fleshing-out of Cells -- why stop at the slot, 
or force everything to /be/ a slot to depend on it?

Meta-cool is that you are the first Cells user to do something like 
this, IIRC, altho there are several who took the more typical Lisper 
approach of dashing off to do their own versions of the entire package. :)



> 
> 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)

I have not looked at the code so maybe what I am about to suggest is 
already possible, but would this also be useful (just to confuse things 
I changed with-stored to bwhen-c-gethash:

    (c? (if (^whatever)
           42
          (bwhen-c-gethash (user login-id *user-logins*)
              .....)))

The above might be easily done (just a tweak or two) by looking at how 
synapses work. They are like local and/or anonymous Cells. "Anonymous" 
because they do not mediate a slot, they mediate an arbitrary sub-form 
of a rule. "Local" because only the Cell envalued by the containing form 
depends on the synaptic Cell.

Historical note: synapses used to be a completely different data 
structure with distinct code supporting them, now we just have a 
"synaptic" attribute to guide the general Cells logic in a few places.

Anyway, then c?-with-stored is just the special case where this appears 
as the entire form:

   (c? (bwhen-c-gethash (...) ...))

Hmmm, you know, I almost never use synapses and yet I have always 
suspected that a lot of fun would be had with them in re expanding the 
semantics one could express with Cells. But this exchange has me 
wondering if I missed something: will new kinds of Cells tend to be 
synapses because the semantics will be useful within rules?

Or maybe I am just confused: should all cells be synapses now? I might 
be in the land of distinctions without differences now. :)

Well, I am off to Amsterdam shortly and will play with this when I get 
back. Not sure how much time I will be on-line, btw, until Monday.

Thanks for a cool contrib.

kt


> 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
> _______________________________________________
> cells-devel site list
> cells-devel at common-lisp.net
> http://common-lisp.net/mailman/listinfo/cells-devel
> 




More information about the cells-devel mailing list