1. 3
  1.  

  2. 1

    That’s a very interesting concept and library. Did you use a specific algorithm for identifying the list of cells that need to be updated given a change? I’ve implemented something similar in JS and am curious about how you deal with cycles and minimizing updates. Using cells that hold values and computation is quite relevant these days, are you developing this for research or for a particular project?

    1. 2

      Did you use a specific algorithm for identifying the list of cells that need to be updated given a change?

      Whoops, I knew I forgot something in the readme. I will soon update it with the next paragraphs.

      There are three reevaluation strategies

      • cached (default): The formula is reevaluated when a term it depends on changes. The result is cached for reads.
      • reeval: The formula is reevaluated every time it is read.
      • on first read: The formula is reevaluated the first time it is read after one of the terms it depends on has changed. The result is cached for reads.

      The calc parameter is passed to Ex to indicate which one to use. For example Ex(`foo + 3, calc="reeval"). It is thus possible to have a document with mixed reevaluation strategies.

      I’ve implemented something similar in JS

      Do you have a link if its freely available?

      and am curious about how you deal with cycles and minimizing updates.

      As you can see its not very smart. If x1 depends on x2 and x2 depends on x3 and … x(n-1) depends on x(n) and y depends on all x then its possible y is re-evaluated n times when x(n) changes instead of just once.

      I think I had a previous (unreleased) version which figured out all values that will be changed and then decide on an optimal reevaluation order (using topological sort) but in my case, it seems different caching strategies was actually more important.

      It is also not smart about things like x if y else z. Even when y is false, changing x still results in a reevaluation.

      It doesn’t detect cycles so when they happen, the resulting behaviour is unexpected. But because all values a formula depends on needs to exist when the formula is created, its a bit harder to make cycles in the first place. Basically, some constant value needs to be a placeholder and then depending on caching strategies, you can get different behaviour for a cycle.

      Using cells that hold values and computation is quite relevant these days, are you developing this for research or for a particular project?

      I’m using it in guitktk. What are some other projects that use cells? I only know of Apparatus which inspired that portion of my project (although I haven’t looked at its source and don’t know if internally they are handled the same).

      Edit to add answer about cycles.

      1. 2

        Thanks for the answers! The first time I came across the notion of cells was when studying Functional Reactive Programming in the 2000s, an I think the first reference to the notion of cells I found was the CLOS Cells library. Over the years, I’ve experimented with different architectures and implementations. One is integrated with React on the UIS data portal with the cells module available here (it’s transpiled from Sugar, but the sources are not available).

        A more recent implementation is available on 3M’s State of Science Index survey where all the component’s state is manage by a cell network, which considerably simplify ensuring the state is always consistent. The transpiled code can be found here and you can see a component’s cell network here.

        Basically, the strategy to improve on what you have by preventing cycles and minimizing updates is to explicitly track inputs and outputs of any cell. Then you can order your cells so that any cell B that depends on A comes after A (you can find an implementation if you look for Successors here). Getting this algorithm right was quite tricky for me, which is why I asked you some questions – I couldn’t find any paper on that specific subject, so I’m always curious to know how others have tackled that issue.

        Your projects seem quite interesting, I hope you’ll be posting more of these :)

        1. 1

          CLOS Cells library.

          I might have come across Cells and Cello at some point but don’t remember what happened when I looked into it. Thanks for bringing it to my attention again since I also mainly want to use cells for UI.

          Looks like the FTP link from the Cello page is broken though. There’s one version here but doesn’t seem to contain screenshot. Cells-gtk has screenshots but I can’t tell where the cells are used.

          I’d be really interested to know how they build up UIs with cells.

          By clicking through some links, I found these slides which talks a bit about algorithms. On slide 28:

          Topo sort does not work: conditional branching means newly travelled paths may emerge on the latest change

          See also slide 35 for an example.

          3M’s State of Science Index survey

          Thanks for both links! I took a quick look (mostly at the comments).

          In models.js (from “-internal”: onwards), it looks like all your cells are reducers? Which “Computes a new value when any of the inputs change”.

          By the way, there are some typos in the comments. For example,

          “the key difference is that the are optimized” should be “they are optimized”.

          “a the SAME values” should be just “the SAME values” (no “a”).

          Your projects seem quite interesting, I hope you’ll be posting more of these :)

          Thanks for the encouragement! Feel free to e-mail me if you want to discuss this some more (my username at email dot com).

          1. 1

            Thanks, I’ll send you an email later today!

            1. 1

              Thanks, just wanted to say that I haven’t received any emails. There’s no rush, at least for me and this is just to let you know.

              I also noticed Lobsters has a private messaging system although I tend to not be logged in.