A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2006-February/060586.html below:

[Python-Dev] Let's just *keep* lambda

[Python-Dev] Let's just *keep* lambdaJosiah Carlson jcarlson at uci.edu
Thu Feb 9 05:51:33 CET 2006
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

More information about the Python-Dev mailing list

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