Where is the Python Journal?
chris patti
cpatti at atg.com
Wed Feb 16 16:14:11 EST 2000
William Annis <annis at biostat.wisc.edu> writes:
> chris patti <cpatti at atg.com> writes:
>
> > poorly understood and badly documented Perl topics) recently wrote
> > a series of articles on 'memoization' - the use of recursion and
> > recursive data structures to implement caching algorithms that save
> > huge gots of time on repeated computations..
> >
> > Python needs something similar.
>
> I couldn't resist, largely because I thought it was so cute
> when I came up with this after a little thought:
>
> class memoize:
> def __init__(self, fn):
> self.fn = fn
> self.args = {}
>
> def __call__(self, *args):
> if not self.args.has_key(args):
> self.args[args] = apply(self.fn, args)
>
> return self.args[args]
>
> if __name__ == '__main__':
> import math
>
> msin = memoize(math.sin)
> print msin(0), msin(math.pi/2), msin(math.pi/4)
> # Continue abusing to your heart's content...
>
> But, I agree about the Python journal idea and I'm also in the
> same boat: getting the Perl Journal despite my apostasy. I suppose we
> shouldn't whine unless we intend to write articles, too. :)
I'm willing, just not qualified :|
I don't personally think there's anything wrong with humbly stating
"I think this thing is needed" it's different from saying "PYthon
Sucks! It doesn't have xx" by a mile :)
Thanks for the memoization snippet, interesting stuff.
-Chris
--
--------------------------------------------------------------------
Chris Patti \ Art Technology Group \ 617-386-1649 \ cpatti at atg.com
--------------------------------------------------------------------
More information about the Python-list
mailing list