Re: Memoizing decorator

2005-12-07 Thread Daishi Harada
Hi, Sorry about the previous dup; I'm posting through Google Groups which seems to have burped. Anyways, I've "improved" things (or at least got things passing more tests). I now bind the cache to each object instance (and class for classmethods). At least one issue still remains, mostly due to

Re: Memoizing decorator

2005-12-07 Thread Daishi Harada
Hi Bengt, Thanks for your reply. >First, I would suggest thinking about the exact semantics of method >memoization. E.g. suppose you write > > class Oops(object): >def __init__(self, factor): self.factor = factor >@memoize_fn >def mul(self, x): >return self.f

Re: Memoizing decorator

2005-12-07 Thread Daishi Harada
Hi Bengt, Thanks for your reply. >First, I would suggest thinking about the exact semantics of method >memoization. E.g. suppose you write > > class Oops(object): >def __init__(self, factor): self.factor = factor >@memoize_fn >def mul(self, x): >return self.f

Re: Memoizing decorator

2005-12-05 Thread Alex Martelli
Scott David Daniels <[EMAIL PROTECTED]> wrote: > Daishi Harada wrote: > > ... I've managed to get these working for both > > functions and methods by wrapping them in > > yet another function (the following is for the > > cookbook example, replacing 'cachedmethod'): > > > > --- > > def memoize(f

Re: Memoizing decorator

2005-12-05 Thread Bengt Richter
On 5 Dec 2005 16:15:38 -0800, "Daishi Harada" <[EMAIL PROTECTED]> wrote: >Hi, > >I'm trying to find/write a memoizing decorator >that works both for functions and methods. ISTM you can't do that without defining exactly what the instance that a metho

Re: Memoizing decorator

2005-12-05 Thread Scott David Daniels
Daishi Harada wrote: > ... I've managed to get these working for both > functions and methods by wrapping them in > yet another function (the following is for the > cookbook example, replacing 'cachedmethod'): > > --- > def memoize(function): > im = Memoize(function) > def fn(*args, **kwa

Memoizing decorator

2005-12-05 Thread Daishi Harada
Hi, I'm trying to find/write a memoizing decorator that works both for functions and methods. I've been looking at the following two samples: http://wiki.python.org/moin/PythonDecoratorLibrary#head-11870a08b0fa59a8622201abfac735ea47ffade5 http://aspn.activestate.com/ASPN/Cookbook/Pyt