Re: conditional computation

2006-10-27 Thread robert
> Robert, that's not the point. I do have enough Python knowledge to > understand this (totally trivial) code !-) > > What I don't understand is how this code is supposed to save you from > having to actually write both complex-key-expr and > expensive-calc-expression more than once. You need them

Re: conditional computation

2006-10-27 Thread Bruno Desthuilliers
robert wrote: > Bruno Desthuilliers wrote: >> 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] >excep

Re: conditional computation

2006-10-27 Thread robert
Bruno Desthuilliers wrote: > 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:#<

Re: conditional computation

2006-10-27 Thread Bruno Desthuilliers
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 >>> re

Re: conditional computation

2006-10-27 Thread robert
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

Re: conditional computation

2006-10-26 Thread Bruno Desthuilliers
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-exp

Re: conditional computation

2006-10-26 Thread robert
Mike Kent wrote: > robert wrote: >> I want to use a computation cache scheme like >> >> >> o = CACHECOMPUTE complex-key-expr expensive-calc-expr >> >> >> frequently and elegantly without writing complex-key-expr or >> expensive-calc-expr twice. >> So its ugly: >> >> _=complex-key-expr;

Re: conditional computation

2006-10-26 Thread Fredrik Lundh
robert wrote: > I want to use a computation cache scheme like > > o = CACHECOMPUTE complex-key-expr expensive-calc-expr > > frequently and elegantly without writing complex-key-expr or > expensive-calc-expr twice. > So its ugly: > > _=complex-key-expr; o=cache.get(_) or > cache

Re: conditional computation

2006-10-26 Thread robert
Gabriel Genellina wrote: > At Thursday 26/10/2006 16:30, robert wrote: > >> I want to use a computation cache scheme like >> >> >> o = CACHECOMPUTE complex-key-expr expensive-calc-expr >> >> >> frequently and elegantly without writing complex-key-expr or >> expensive-calc-expr twice. >>

Re: conditional computation

2006-10-26 Thread Mike Kent
robert wrote: > I want to use a computation cache scheme like > > > o = CACHECOMPUTE complex-key-expr expensive-calc-expr > > > frequently and elegantly without writing complex-key-expr or > expensive-calc-expr twice. > So its ugly: > > _=complex-key-expr; o=cache.get(_) or > cache

Re: conditional computation

2006-10-26 Thread Gabriel Genellina
At Thursday 26/10/2006 16:30, robert wrote: I want to use a computation cache scheme like o = CACHECOMPUTE complex-key-expr expensive-calc-expr frequently and elegantly without writing complex-key-expr or expensive-calc-expr twice. So its ugly: _=complex-key-expr; o=cach

conditional computation

2006-10-26 Thread robert
I want to use a computation cache scheme like o = CACHECOMPUTE complex-key-expr expensive-calc-expr frequently and elegantly without writing complex-key-expr or expensive-calc-expr twice. So its ugly: _=complex-key-expr; o=cache.get(_) or cache.setdefault(_,expensive-calc-