[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Accumulator Reduc




> From: "Fredrik Lundh" <fredrik@pythonware.com>
> Date: Thu, 30 May 2002 10:46:49 +0200
> 
> > > you _can_ make Python as ugly and almost
> > > as compact as the lisp example:
> > > 
> > > from operator import setitem
> > > foo = lambda n: lambda i,s=[n]: setitem(s,0,s[0]+i) or s[0]
> > 
> > Yuck! This depends on so many accidental side-effects of various Python
> > features that it would take too much effort to explain why it works. But
> > still amusing.
> 
> here's an other variant:
> 
>     def foo(i, s=mutable_int(0)): s += i; return s
> 
> </F>
> 
> 

What version of python is that?  It doesn't work in 2.2.1.

Mike