Friday, March 25, 2016

AlternateLambdaSyntax - Python Wiki

It's fun to see the Python guys thrashing over lambda syntax.  Eventually Guido gave in and kept the historic lambda syntax.



AlternateLambdaSyntax - Python Wiki: "AlternateLambdaSyntax"



'via Blog this'



I must admit, I find the Python lambda syntax a bit unpleaasant:



Ordinary function

def foo(x):
      return x+1
Lambda

lambda  x: x+1
It is a pity thaat Pythin's lambdaas are not multiline:

http://stackoverflow.com/questions/1233448/no-multiline-lambda-in-python-why-not



This seems to be aa consequence of Python not being indentation sensitive inside parens.



I think that it is also a pity that Python's lambdas are strictly anonymous - although you can assign them a named variable.



I personally often use lambdas not just for anonymous functions, but also for named functions that I want to define near point of use, in the narrowest scope possible.



Even if they could be a lambda, naming them gives nicer stack traces.


No comments:

Post a Comment