Lots of people want them (lots of people don't, too), but no one has come up with a great syntax that plays nice with the rest of Python and saves you much over named functions.
x('.b', onclick=func ev:
print("clicked")
end)
You're welcome.of course it matters, there are design decisions in languages. a certain pattern or syntax may feel just right in one language but very much wrong in another.
Throwing in an `end)` like that feels wrong in python
Once you have the scaffolding of the syntax you can turn it over to the bikeshedders on the mailing list to make it pretty.
def begin(*args):
return args[-1]
begin(
func := lambda x, y: begin(
z := int(input()),
x + y + z
),
func(1, 2)
)You may already be aware, but not everyone is: they capture variables from outer scopes in exactly the same way that lambdas do.
Given the recent success of anonymous functions and it's widespread use and impact in other languages, like Javascript, C#, Java, C++11, maybe it's time to re-evaluate that opinion. I mean, what would javascript be today without promises and multi-line anonymous functions?
But, it’s still unlikely that we’ll see full anonymous functions in Python. They just don’t work with its significant-indentation syntax.
Guido laid out the challenges of multiline lambdas on a mailing list [1] and then followed up with a blog post [2] [3]. His chain of thought is worth reading in full, but the crux is lack of “Pythonicity” and his gut feel that named functions avoid the complexity and possible ambiguity of multiline lambdas:
def callback(x, y):
print x
print y
a = foo(callback)
[1]: https://mail.python.org/pipermail/python-dev/2006-February/0... "[Python-Dev] Let's just keep lambda"[2]: https://www.artima.com/weblogs/viewpost.jsp?thread=147358 "Language Design Is Not Just Solving Puzzles"
[3]: https://news.ycombinator.com/item?id=20672739 "Language Design Is Not Just Solving Puzzles (2006) | Hacker News"