Jiwon Seo <seojiwon at gmail.com> wrote: > On 2/8/06, Josiah Carlson <jcarlson at uci.edu> wrote: > > Closures already exist in Python. > > > > >>> def foo(bar): > > ... return lambda: bar + 1 > > ... > > >>> a = foo(5) > > >>> a() > > 6 > > Not in that we don't have anonymous function (or closure) with > multiple statements. As already said, lambdas (Python's anonymous functions) are limited to a single expression. If you can't do what you want with a single expression, then it probably SHOULD have a name, so you should use a standard function definition. > Also, current limited closure does not capture > programming context - or variables. You should clarify yourself. According to my experience, you can do anything you want with Python closures, it just may take more work than you are used to. def environment(): env = {} def get_variable(name): return env[name] def set_variable(name, value): env[name] = value def del_variable(name): del env[name] return get_variable, set_variable, del_variable - Josiah
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4