Automatic caching and dependency evaluation among variables?

Discussion in 'Python' started by Ori Berger, Apr 29, 2004.

  1. Ori Berger

    Ori Berger Guest

    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).
     
    Ori Berger, Apr 29, 2004
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Fuming Wang
    Replies:
    7
    Views:
    336
    =?iso-8859-1?q?Fran=E7ois_Pinard?=
    Jul 17, 2003
  2. Ilias Lazaridis
    Replies:
    2
    Views:
    392
    Ilias Lazaridis
    Apr 24, 2005
  3. Kermit Mei
    Replies:
    1
    Views:
    249
    Kermit Mei
    Sep 23, 2008
  4. Ilias Lazaridis
    Replies:
    74
    Views:
    763
    Ilias Lazaridis
    Apr 4, 2005
  5. Ilias Lazaridis
    Replies:
    18
    Views:
    333
    Bill Guindon
    Apr 9, 2005
Loading...

Share This Page