Have you considered modelling this as a functional problem first?

So perhaps start out with an immutable data structure to model your cells:

    (def cells
      {:x [:const 1]
       :y [:const 2]
       :z [:derive [:x :y] (fn [x y] (+ x y))]}

Then you could use a function to calculate the value:

   (calculate cells)
   => {:x 1, :y 2, :z 3}

If you want cells to act more like refs, then you can keep a global
database:

    (def cells-data (atom {})

Then use an watch on the atom to keep a cache of the calculation whenever
the cells change.

When you create a cell, it adds to the global database. When you deref a
cell, it just refers to the cached calculation.

If you need more performance than an atom, you could use something like the
megaref <https://github.com/cgrand/megaref> library.

- James

On 26 March 2016 at 12:07, hiskennyness <kentil...@gmail.com> wrote:

> Follow-up question: how do I test that I am collision-proof?
>
> Perhaps:
>
>    1. Kick off two threads (call them 1st and 2nd) 100ms apart
>    2. Have them update the same ref
>    3. Have 1st do the initial reset! to the ref then sleep for 200ms
>    4. 2nd just charges ahead
>    5. Check that each took full and complete effect, with 2nd appearing
>    before 1st (do I have that right? Collisions are detected when a dosync
>    finishes and attempts to write to the refs?)
>
> How'm I doin?
>
> Thx, hk
>
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with
> your first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
> ---
> You received this message because you are subscribed to the Google Groups
> "Clojure" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to clojure+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to