Lazy spreadsheet

  1. 6 months ago
    Edited 6 months ago by Zero

    The whole thing is going to be a network of cells, where each cell holds values that depend on values from other cells. We'll use the observer pattern to propagate value modifications: each cell maintains a list of its dependents, called observers, and notifies them automatically of any state changes.

    A cell contains a bag. Values of the cells it observes are transfered to its bag, so the cell's value is calculated. When it's done, the cell is flagged up-to-date.

    It works like a spreadsheet. But we don't want values to be calculated automatically, because it would be a huge waste of energy. What we want is a lazy spreadsheet.

    When an observed cell changes its value, instead of propagating its new value, it just emits a need refresh message. When cells receive this message, they set their up-to-date flag to false and propagate the same message to all their observers, if it has not be done already.

    The system tends to be standing by. When a particular value, on a specific cell, is needed, if this cell's up-to-date flag is true, we get the value instantly. If it's false, the cell sends a calculate now message to the cells it observes, to get the new value.

    When a cell receives a calculate now message, if its value is up-to-date, it returns it, else it propagates the calculate now message to the cells it observes.

    So, we have two types of messages: the need refresh message, flowing from observed to observers, and the calculate now message, flowing from observers to observed.

    A "function" is no longer linear, but rather automatically determined to produce a value when needed, depending on what's already known and what's not yet. In this context, "calling" a function consists of: setting some cell's values (these are the parameters), sending a calculate now message to a target cell (this is the function call), and getting the target cell's value (the "return" value).


or Sign Up to reply!