Hacker News new | past | comments | ask | show | jobs | submit login

> Am I the only one who wants multi-lined anonymous functions in Python?

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.




Hey Pythonistas

    x('.b', onclick=func ev:
        print("clicked")
    end)
You're welcome.


`end`? In my Python?!


It's more likely than you think. You need some end delimiter, it doesn't matter what it is as long as there is one. Just like list literals end with ] and dict literals end with } and str literals end with " or ' etc.


> it doesn't matter what it is as long as there is one

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

https://www.python.org/dev/peps/pep-0020/


It doesn't matter functionally. You can make the end token "waffleiron" or "mariahcarey" or "%^*~$". But there does need to be an end token to make multiline lambdas work and recognizing that is the first step to solving the problem.

Once you have the scaffolding of the syntax you can turn it over to the bikeshedders on the mailing list to make it pretty.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: