Python Closures

Ben Wolfson wolfson at midway.uchicago.edu
Fri Dec 8 22:01:45 EST 2000


More-or-less closures can be used in Python with, of course, the
lambdabuse module.  Observe:

>>> import lambdabuse as l
>>> l.Def('make-adder', lambda n: l.Def(l.ANONYMOUS,
				    lambda x: x + l.Val('n')))
Call_Wrapper instance: make-adder
>>> add4 = l.Call('make-adder', 4)
>>> add4(9)
13
>>> 

Source for the module is at 

http://home.uchicago.edu/~wolfson/Python/lambdabuse.py
                                        /LambdaDict.py
                                        /LambdaEnv.py
or + .html for colorization.

-- 
BTR
It infuriates me that Dracula may have needed my soul more than I do.
 -- Stanley Donwood, "Dracula"




More information about the Python-list mailing list