Python syntax in Lisp and Scheme
Lulu of the Lotus-Eaters
mertz at gnosis.cx
Sat Oct 4 16:19:48 EDT 2003
Alex Martelli <aleax at aleax.it> wrote previously:
|> >>> def foo(i, accum=[0]):
|> ... accum[0]+=i
|> ... return accum[0]
|...cannot just instantiate multiple independent accumulators
|Making a cookie, and making a cookie-cutter, are quite different
True... just like there's a difference between a function and a function
factory (it's quite a close analogy, really):
>>> def foofactory(start):
... def foo(i, accum=[start]):
... accum[0]+=i
... return accum[0]
... return foo
>>> x = foofactory(7)
>>> y = foofactory(2)
>>> x(1)
8
>>> y(2)
4
>>> x(2)
10
But that's pretty close to what a couple other people have suggested.
Yours, Lulu...
--
Keeping medicines from the bloodstreams of the sick; food from the bellies
of the hungry; books from the hands of the uneducated; technology from the
underdeveloped; and putting advocates of freedom in prisons. Intellectual
property is to the 21st century what the slave trade was to the 16th.
More information about the Python-list
mailing list