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

Re: Accumulator Reduc



> > 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>