I actually like the “(x, y=7) => x + y” and “async (x, y) => asyncio.sleep(x + y)” for both normal and async anonymous functions respectfully. I have natural aversion to the word lambda for some reason. The normal anon function has “return” implicitly, and the async anon function has “return” implicitly as well. Usage: f1 = (x, y=7) => x + y f1(3) outputs 10 f2 = async (x, y) => asyncio.sleep(x + y) async def main(): coro = f2(3, 7) await coro return “waited 10 seconds” result = asyncio.run(main()) print(result) # outputs “waited 10 seconds”
Also, this is very close to what I brought back to discussion some time ago, which is typing.Callable.. instead of =>, we do -> for it. Correct me guys if you find any mistakes in the above. Python with those new proposal and Match Pattern will be so much more elegant. Abdulla Sent from my iPhone > On 12 Feb 2021, at 12:57 PM, Brendan Barnwell <brenb...@brenbarn.net> wrote: > > On 2021-02-11 03:24, J. Pic wrote: >> Hi all, >> >> Lambdas can be defined as such: >> >> w = lambda: [12] >> x = lambda y: len(y) >> >> I'd like to propose the following: >> >> w = (): [12] >> x = (y): len(y) >> >> Or even another contraction for when there are no arguments: >> >> w =: [12] > > I don't see any need for this. It's even more cryptic than "lambda" > because at least lambda is a word you can look up. This is just inscrutable > punctuation. Using different punctuation like "=>" doesn't help. > > The only thing that would be better than lambda is a less confusing > keyword. So like "func x: x+2" would be better than "lambda x: x+2". That > probably won't happen because no one wants to add new keywords. But adding > new non-keyword ways to do this isn't worth it just to save a few keystrokes. > > -- > Brendan Barnwell > "Do not follow where the path may lead. Go, instead, where there is no path, > and leave a trail." > --author unknown > _______________________________________________ > Python-ideas mailing list -- python-ideas@python.org > To unsubscribe send an email to python-ideas-le...@python.org > https://mail.python.org/mailman3/lists/python-ideas.python.org/ > Message archived at > https://mail.python.org/archives/list/python-ideas@python.org/message/ZGJ5WAI7YKMPSXWXOKNADRCP44SFR262/ > Code of Conduct: http://python.org/psf/codeofconduct/ _______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/GKI3B6DQJUDWU6H72SRB4S6PJLGC5N6Z/ Code of Conduct: http://python.org/psf/codeofconduct/