Lambda going out of fashion

Robert Brewer fumanchu at amor.org
Fri Dec 24 03:22:17 CET 2004


Nick Coghlan wrote:
> ...rather than pushing to retain lambda for Py3K, it might
> be more productive to find a better statement -> expression
> translation for function definitions. Guido seems to prefer
> named functions, so it would still be tough to gain his
> acceptance. However, a more Pythonic syntax is the only way
> I can see anonymous functions making into 3.0
> 
> The current best example of a statement->expression translation
> is generator expressions:
> 
> def squares(seq)
>    for x in seq:
>      yield x * x
> 
> total = sum(squares(seq))
> 
> versus:
> 
> total = sum(x * x for x in seq)
> 
> If we consider a function definition (omitting decorators
> and docstrings) we get:
> 
> def foo(a, b, c):
>    return f(a) + o(b) - o(c)
> 
> accepts_func(foo)
> 
> What would a Pythonic 'function as expression' look like?

Or simply:

accepts_func( (f(a) + o(b) - o(c) for a, b, c) )

...but that would give whomever writes the parser a headache. ;)


Robert Brewer
MIS
Amor Ministries
fumanchu at amor.org



More information about the Python-list mailing list