-
-
Save ds300/e999180e504c81bae0f3 to your computer and use it in GitHub Desktop.
; So given this: | |
(def cellcell (cell (cell 5))) | |
; My question boils down to whether there is any way to make a cell which | |
; contains the value of the inner cell of cellcell regardless of whether we do | |
; things like | |
(reset! cellcell (cell 10)) | |
; or | |
(reset! @cellcell 15) | |
; the naive thing is | |
(def value (cell= @cellcell)) | |
; but that doesn't work for the latter case because only cellcell is | |
; hooked up to the propagation graph. | |
; So by 'Can formula cells have dynamic set of inputs?' I mean: | |
; Can the propagation graph structure be influenced by the contents of cells? | |
; Or is it fixed at the point when the 'lifted' functions returned by `formula` | |
; are invoked? |
Does that mean if, at the end, you still had a reference to the original inner cell containing 15
, incrementing it would print 16
?
That's right. If we had weak references, the JavaScript GC could deem such cells unreachable/immutable for us, and formulas would be collected automatically. Unfortunately, it doesn't look like JavaScript will get them anytime soon, if ever.
Will WeakMap and its polyfills help us?
@ul sadly no... WeakMap is only really suitable for caching, or similar scenarios where the consumer supplies the key. Since they're not iterable, they're not suitable for general weak storage, which is how we would want to use them - to store a weak collection cell references that could be iterated through. WeakReference really is the thing we want, since we could make them values in our priority map, and the propagator could discard entries nulled by the GC.
This is one way:
An implication of this is that after
reset!
, the first formula over(fn [c] ...)
was not explicitly destroyed, and so will not be garbage collected.