conditional computation

Bruno Desthuilliers onurb at xiludom.gro
Fri Oct 27 14:00:23 CEST 2006


robert wrote:
> Bruno Desthuilliers wrote:
>> 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 KeyError:            #<--------- was error           
>>> 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 ?
> 
> the complex-key-expr is written only once in the code

How do you get something back from the cache then ?

> expensive-calc-expr is  written only once in code 

Same problem here...  I fail to understand how you intend to use this
"cache".



-- 
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in 'onurb at xiludom.gro'.split('@')])"



More information about the Python-list mailing list