Sometimes, for reasons of style and clarity, I want to define a function inline, but python doesn't allow me to. It forces me to do:
def x(bar, fram):
z = foo(bar, fram)
baz(z)
button.onClick(x)
When in some cases, I would like to express it as: button.onClick(
def (bar, fram):
z = foo(bar, fram)
baz(z)
)
So I get that it's never necessary, but I find it sometimes limiting as an author who cares strongly about how his code is organized. button.onClick(lambda bar, fram: baz(foo(bar, fram)))
The problem with embedding procedure definitions within parameter lists is indentation. Languages such as JavaScript or Ruby use explicit syntax for indentation, which allows a degree of flexibility in how procedure literals are defined. Python uses only whitespace, so trying to extend the grammar to support arbitrary procedure literals would be very difficult (according to Guido).Anyway, I'm familiar with why Guido doesn't want them, and I totally respect it, and I write 99% of my personal code in python, so I clearly don't think it's a huge deal. It's just something I wish python did have, is all.
Nothing other than an if statement, a goto, and some basic arithmetic is needed in a programming language. It's all syntactic sugar. I agree that such a construct would be useful. However, it's more about if it's worth complicating the language over. I don't necessarily know how complex that would make things, but I can definitely see that a case can be made that it would be more trouble than it's worth considering the way indentation is handled.
class Somebutton(Button):
def onClick(self):
.....
def onSomethingElse(self):
.....
only one line of overhead (class line). And I'm pretty sure you can hack __dict__ in init, or use metaclasses so that the events are chained automatically, even without calling `Button.onClick(self)`. You can construct / add the object to it's container the same way (Somebutton(), instead of Button())In my experience (mostly JS and AS) they rather usually lead to little pieces of logic scattered all over the place and insufficient decoupling.
As statements are not allowed in lambdas this means you either are stuck writing a local named function and writing the code in idiomatic python or writing some helper functions to allow you to write code in a functional but non-idiomatic python style.
It comes down to a matter of style.
My personal theory is that once a python programmer discovers the magic of itertools they are about 3 months from looking for a new language that supports the functional style more naturally.
People are down on I statement Lambdas because they don't do all of the above so well.
Once you have good syntax established for using lamdba-s in any form - they would be used. First users would be as I've put above - callbacks of sort (GUI, IO, etc.)