I’m trying to implement spreadsheet like functionality where it maintains variables and updates them correctly when other variables or “cells” change.
The only implementation I have seen so far is one that stores the inputted data in a string and evaluates it, however when data changes and cells need to be recalculated it always needs to evaluate the strings again.
What I’m simply wondering is if it’s possible at all to parse a string like Cell1 = “SQUARED (4)” into Cell1 = squared 4
So instead of the value being calculated into the cell, but the string needing to be run again and again when recalculations are necessary, it can instead save the actual functions and values somehow, somewhere, so that parsing and evaluating only needs to happen once.
If this isn’t possible then I’ll need to create a code-generator because I need things to be really fast and can’t afford heavy performance loss. The speed of evaluation, compiling, ect, does not matter. It’s the speed after all cells have been created, when the input data changes millions of times and propagates through the “spreadsheet” like system that matters.
So this is first of all just a yes or no question. If possible then any examples would of course be helpful. Edit: Well I guess it would be really helpful, since I can’t figure this out myself.
There is a quite good example from Don Syme’s blog on memoization – https://blogs.msdn.com/b/dsyme/archive/2007/05/31/a-sample-of-the-memoization-pattern-in-f.aspx?Redirected=true
You write this function
Then you can create a memoized function like: