What is a spreadsheet? It’s a bunch of nodes tied with dependencies. Some of the nodes are pure data, others are code.
It’s a DAG. And you know who has wrote library that processes DAGs as tasks? This guy! it’s called Croupier.
So, some cells are just a value with a key: Sheet1!A1 => 42
Other cells are code: Sheet1!A2 => =A1+2
But of course the code is in “Excel formula language” … how if there was a parser for it? There are a bunch. I liked one called “formulas” in Python. So I ported it to Crystal, and that creates a AST.
Of course one can use a AST to generate code. So it could generate Crystal code. Which could be defined as Croupier tasks. Of course the parser knows EXACTLY the dependencies. So the tasks can be wired to do the right thing.
So then you can compile the “spreadsheet” into a program.
And the cells that are just data don’t need to recompile the program, they are just data, you update, then croupier reruns ONLY the tasks that need running, updating ONLY the cells that need updating, and can even do that on multiple threads.
Wow why did I not know that a spreadsheet is a DAG! In retrospect after reading your breakdown it makes lots of sense but I guess I never thought about this
Ok, it now supports editing cells (no recompilation) and formulas (automatic recompilation) mouse click, double click, and wheel events, and so on (ui branch). TBH it’s a state of the art spreadsheet for 1984
I am shocked this went this well in … about 6 hours of work?
Something I wanted to have in the past is a spreadsheet engine that would allow overlays. As in I have a spreadsheet and I can open multiple working sessions on it, in memory, and apply some changes each session while sharing common resources. Not starting from scratch motivates me, now I just need … time :-P
pushing the idea further, I wonder if it wouldn’t make sense to interpret instead of compile, until you’re done with the formulas, and then compile to get the released spreadsheet
One accidental feature is that if you only have the “spreadhseet binary” but not sheety itself, you can’t edit formulas, only data, so it works as … a modeling tool?
This thread made me realize that something that’s been a bit of a challenge at work (content dependencies), is basically a DAG issue. Build the DAG, and if it starts going cyclic, error out.
I kinda got motivated after this and finally cleaned up a bunch of bugs and added wide char support, now the lib handles Unicode width much more reliably (including CJK and emoji), and rendering/state edge cases are a lot tighter than before.