On Saturday, March 26, 2016 at 8:53:24 PM UTC-4, James Reeves wrote: > > Have you considered modelling this as a functional problem first? >
Well. I was doing that in Cells 0.1, which was invented to manage DUI layout no matter what wanted to be positioned or sized relative to what attribute of what object (as long as no circularity was attempted). Worked great but quickly failed on scalability as formula depended on formula so we quickly moved to caching calculated values and then a scheme to know when the cache was obolete. > 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. > Oh, cool, I did not know about watch. Maybe I can use that somewhere. But having the whole model (which can have hundreds of datapoints mediated by cells all in one global atom might be a little too unspecific when a change comes along. > 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://www.google.com/url?q=https%3A%2F%2Fgithub.com%2Fcgrand%2Fmegaref&sa=D&sntz=1&usg=AFQjCNHLgzXX4910FB4U5YJtIhh1fpbP8Q> > library. > Intriguing! Right now the Cells library orders everything so no two updates can run concurrently, but something like megarefs could let me relax that yet retain much consistency. Thank for the input. -kenneth > > - James > > On 26 March 2016 at 12:07, hiskennyness <kent...@gmail.com <javascript:>> > 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 clo...@googlegroups.com >> <javascript:> >> Note that posts from new members are moderated - please be patient with >> your first post. >> To unsubscribe from this group, send email to >> clojure+u...@googlegroups.com <javascript:> >> 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+u...@googlegroups.com <javascript:>. >> 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.