Automatic caching and dependency evaluation among variables?

Ori Berger i.dont.like.spam at spamfree.final.nospam.co.unspammed.il
Thu Apr 29 14:12:55 EDT 2004


I *think* I saw a post some time ago enabling "spreadsheet" like 
computations, that allows something along the lines of:

 >>> vars.a = 10
 >>> vars.b = dependency("vars.a * 20")
 >>> print vars.b
200
 >>> vars.a = 50
 >>> print vars.b
1000

(Not sure what the actual syntax definitions were)
And vars.b was only re-computed if vars.a was changed - 
otherwise a cached value was returned.

I can write this myself, but the solution I'm thinking of is 
inelegant, and I remember the solution was extremely short and 
elegant; I can't find anything in the google archives, though.

Anyone perhaps have a link or other helpful info?

(My idea of how to do it: make vars a special dict that logs 
every __get__, and that can have callbacks when something is 
__set__. the dependency() code would evaluate the expression, 
see what __get__s were logged, and attach the same expression to 
be reevaluated when any of those were __set__.

It becomes complicated, though, if I wish to track changes to 
vars.subvar1.subvar2.subvar3 as well, though).



More information about the Python-list mailing list