First, just a point of information: do I understand correctly that the original example below uses an assoc instead of your store just to simplify the problem and highlight the key issue?<div><br></div><div>I am guessing yes, so I will charge ahead with my thoughts: basically you need to make the lookup itself establish a dependency. I had assumed that this what you had done when you said you had created a cells-aware store. I was guessing that behind the scenes there was a second hashtable with the same key but a value that was a list of the cells that had looked it up. (Or you could try stuffing the thing stored with a list of asking cells in the one hash-value.) That would have gotten you into c-link, c-unlink, and other good stuff.</div>
<div><br></div><div>And then you are done. Everything (including sensible optimization) just flows from that.</div><div><br></div><div>Sorry if I am all wet or if not for not examining your code earlier. I'd look now but jet lag beckons. I'll try later or just let me know if this is making sense.</div>
<div><br></div><div>cheers, kenny</div><div><br></div><div>ps. I did not stare too hard either at your deferred optimizarion or something idea because I saw this other more standard approach to the problem, but again if it turns out I missed something I'll stare at that too when I recover a little. k</div>
<div><br></div><div>pps. Interesting idea: if things never go away you can lose the dependency of the seeker on the store once the sought key appears. Not sure how to express that, unless we tackle the not-to-be issue by doing something I have toyed with before (and might even still be out there): a rule that says when an instance dies. In the case where that is a hardcoded nil or a rule that produced nil and then got optimized away, the cells-store could drop the dependency from its side after propagating to the asker. k</div>
<div><br></div><div><br></div><div><br><div class="gmail_quote">On Wed, Apr 16, 2008 at 11:26 AM, Peter Hildebrandt <<a href="mailto:peter.hildebrandt@gmail.com">peter.hildebrandt@gmail.com</a>> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
While working on the hash-table lookup for md-names (as an alternative<br>
to fm-other) I came across an interesting phenomenon: Some rules die,<br>
others don't.  Following the XP idea for RFEs, I'll try to present a<br>
test case:<br>
<br>
(defpackage :c-test (:use :cl :cells :utils-kt))<br>
(in-package :c-test)<br>
<br>
(defparameter *hash* (make-hash-table))<br>
(defun val (name) (bwhen (obj (gethash name *hash*))<br>
                            (value obj)))<br>
<br>
(defparameter *m1* (make-instance 'model :value (c? (bif (v (val<br>
:foo)) (1+ v) 'nothing))))<br>
(assert (eql (value *m1*) 'nothing))<br>
<br>
(setf (gethash :foo *hash*) (make-instance 'model :value (c-in nil)))<br>
<br>
(defparameter *m2* (make-instance 'model :value (c? (bif (v (val<br>
:foo)) (1+ v) 'nothing))))<br>
<br>
(assert (eql (value *m1*) 'nothing))<br>
(assert (eql (value *m2*) 'nothing))<br>
<br>
(setf (value (gethash :foo *hash*)) 42)<br>
(assert (eql (value *m1*) 43))  ;;; #### FAILS ####<br>
(assert (eql (value *m2*) 43))  ;;; ok<br>
<br>
(setf (value (gethash :foo *hash*)) 17)<br>
(assert (eql (value *m1*) 18))  ;;; #### FAILS ####<br>
(assert (eql (value *m2*) 18))  ;;; ok<br>
<br>
;;; or with a list<br>
<br>
(defparameter *list* nil)<br>
(defun valb (name) (bwhen (obj (assocd name *list*))<br>
                            (value obj)))<br>
(defparameter *m1b* (make-instance 'model :value (c? (bif (v (valb<br>
:foo)) (1+ v) 'nothing))))<br>
<br>
(assert (eql (value *m1b*) 'nothing))<br>
<br>
(push (cons :foo (make-instance 'model :value (c-in nil))) *list*)<br>
<br>
(defparameter *m2b* (make-instance 'model :value (c? (bif (v (valb<br>
:foo)) (1+ v) 'nothing))))<br>
<br>
(assert (eql (value *m1b*) 'nothing))<br>
(assert (eql (value *m2b*) 'nothing))<br>
<br>
(setf (value (assocd :foo *list*)) 17)<br>
(assert (eql (value *m1b*) 18))  ;;; #### FAILS ####<br>
(assert (eql (value *m2b*) 18))  ;;; ok<br>
<br>
(setf (value (assocd :foo *list*)) 42)<br>
(assert (eql (value *m1b*) 43))  ;;; #### FAILS ####<br>
(assert (eql (value *m2b*) 43))  ;;; ok<br>
<br>
--------<br>
<br>
An interesting indicator might be that the first call to (value *m1*)<br>
returns two values, 'nothing and nil -- does that mean that cells<br>
somehow realizes there that this cell can be optimized out?<br>
<br>
And -- more importantly -- how can I tell cells not to optimize away<br>
the ruled cell in *m1*/*m1b*?<br>
<br>
Thanks,<br>
Peter<br>
_______________________________________________<br>
cells-devel site list<br>
<a href="mailto:cells-devel@common-lisp.net">cells-devel@common-lisp.net</a><br>
<a href="http://common-lisp.net/mailman/listinfo/cells-devel" target="_blank">http://common-lisp.net/mailman/listinfo/cells-devel</a><br>
</blockquote></div><br></div>