Skip to content

Instantly share code, notes, and snippets.

@ds300
Created September 29, 2015 14:07
Show Gist options
  • Save ds300/e999180e504c81bae0f3 to your computer and use it in GitHub Desktop.
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?
@alandipert
Copy link

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.

@ul
Copy link

ul commented Oct 5, 2015

Will WeakMap and its polyfills help us?

@alandipert
Copy link

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment