Jiwon Seo <[EMAIL PROTECTED]> wrote:
> On 2/8/06, Josiah Carlson <[EMAIL PROTECTED]> 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
_______________________________________________
Python-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe:
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com