3 ms·
How does it deal with dependencies between cells? How does it figure out what order to update them in?
by omaranto 16y ago
How does it deal with dependencies between cells? How does it figure out what order to update them in?
- rflrob 16y agoI'd suspect that there's a listing somewhere that says, for a given cell, what other cells depend on it, so it knows to update the others when it's modified. I can't immediately get it to work on my Mac, so I can't test it out, though. There is a line in the source (_datastructures.py) that generates a KeyError("Circular dependency at %s" % str(key)), so I'd guess that it won't let you do anything that generate cycles on the dependency graph. And once the graph is acyclic, it should be fairly obvious in what order to update things.
- gruseom 16y agoThe standard technique is to keep a directed graph with an edge from a cell to each cell that depends on it, then propagate changes recursively. This works well when the total number of cells isn't large.
- omaranto 16y agoRight, but that only works if when looking at a formula you can figure out which other cell it refers to. I guess I asked what I asked because I hoped having Python would let you use computed references --something like cell(x,y) where x and y are expressions computing the row and column, or even eval(str) where the str is a formula that refers to some cells.
- gruseom 16y agoSomehow I didn't see your reply till now. It turns out this problem of computed cell references is a nontrivial one. (Excel can do it, but slowly and I suspect not with full generality.) The trouble is that you need the reference graph to compute the spreadsheet, but now computing the spreadsheet can modify the reference graph, so you have to maintain the graph dynamically as you calculate. I'd be interested in discussing this further if you are, but email would be better than here. (My address is in my profile.)