[Python-ideas] Thoughts on lambda expressions

Alexander Walters tritium-list at sdamon.com
Thu Mar 3 03:25:59 EST 2016


It still comes down to, for me, is ``def foo -> bar(foo)`` really any 
better than ``lambda foo: bar(foo)``?  Are we gaining anything? Does it 
do anything that the lambda keyword does not?  I have been (mostly) 
following this thread, and I cannot really see a real concrete problem 
with the lambda keyword and the colon.

I don't really want to rain on parades here*, but unless something 
amazing can come out of new syntax (new functionality, because the 
readability gain in these proposals is debatable), I really don't think 
the syntax is going to change.

Am I missing some great change in functionality here?  If this 
discussion happened before lambda was added to the language, I think 
this would be a different story.




* ok, I lied, I don't like this suggestion, so maybe I wanted to drizzle 
on it's parade.  A spring shower at best.

On 3/3/2016 02:54, Nick Coghlan wrote:
>> On 3/2/2016 10:48 PM, Nick Coghlan wrote:
>>
>>> I'm personally not averse to adding new syntactic sugar for lambda
>>> expressions, but if we did do something like that, I'd advocate for
>>> just stealing Java's spelling (perhaps with the addition of mandatory
>>> parentheses, ala generator expressions):
>>>
>>> https://docs.oracle.com/javase/tutorial/java/javaOO/lambdaexpressions.html#syntax
>>>
>>> The rationale for that would be:
>>>
>>> 1. "(params -> expr)" is easier on the eyes than "lambda params: expr"
> One qualifier on that: to meet the deliberate LL(1) parsing constraint
> on the language grammar, the actual syntax would probably need to be
> "(def params -> expr)"
>
> Generator expressions and comprehensions don't need an introductory
> token as the first child node is an ordinary expression, so the parser
> doesn't need any advance notice of the larger construct. That isn't
> the case with a parameter list - those have special parsing rules to
> allow things like default arguments, *args, and **kwds.
>
> Cheers,
> Nick.
>



More information about the Python-ideas mailing list