[Python-ideas] Ruby-style Blocks in Python Idea

Terry Reedy tjreedy at udel.edu
Mon Mar 9 23:04:32 CET 2009


Steven D'Aprano wrote:

> Lambdas are single-line (technically, single-statement) anonymous 
> functions,

Lambdas are function-defining expressions used *within* statements that 
give the resulting function object a stock .__name__ of '<lambda>'.  The 
syntax could have been augmented to include a real name, so the 
stock-name anonymity is a side-effect of the chosen syntax.
Possibilities include
   lambda name(args): expression
   lambda <name> args: expression
The latter, assuming it is LL(1) parse-able, would even be compatible 
with existing code and could still be added.

Contrarywise, function-defining def statements could have been allowed 
to omit the name.  To be useful, the object (with a .__name__ such as 
'<def>', would have to get a default namespace binding such as to '_', 
even in batch mode.

> caller(lambda args: statement)

Change 'statement' to 'expression'.

> A multi-line lambda (technically, multi-statement)

The problem is that 'multi-statement expression' is an oxymoron in 
Pythonland.

 > would also be an anonymous function.

Not necessarily, and irrelevant to the essence of lambda expressions, 
which is that they are expressions that can be used within statements.

Terry Jan Reedy




More information about the Python-ideas mailing list