conditional computation

Bruno Desthuilliers bdesth.quelquechose at free.quelquepart.fr
Fri Oct 27 00:47:50 CEST 2006


robert a écrit :
(snip)
> class MemoCache(dict): # cache expensive Objects during a session 
> (memory only)
>    def memo(self, k, f):
>        try: return self[k]
>        except IndexError:
>            return self.setdefault(k, f())
> cache=MemoCache()
> ...
> 
> o = cache.memo( complex-key-expr, lambda: expensive-calc-expr )
> 

And how do you get back the cached value without rewriting both 
complex-key-expr *and* expensive-calc-expr ? Or did I missed the point ?



More information about the Python-list mailing list