On Fri, 12 Feb 2021 at 09:26, Abdulla Al Kathiri
<alkathiri.abdu...@gmail.com> wrote:
>
> 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 think it's a reasonable syntax, although it could be over-used.
That's not an issue with the syntax, though - *anything* can be
over-used :-) Experience with similar syntax in other languages
suggests this would be useful.

> I have natural aversion to the word lambda for some reason.

It does seem to cause people (including me!) a lot more problems than
one would expect, on the face of it. Maybe because it's not a common
term outside of computer science? But the endless debates over
alternative keywords have never come up with anything else that people
can agree on.

> 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”

I'm not sure what the use cases would be for an async lambda - the key
is that it's not named, so the above isn't a good example as it's just
as easy to write

async def f2:
    return asyncio.sleep(x+y)

(Excuse any errors here, I'm not that familiar with asyncio).

If there are good use cases, I think it makes sense to include async
lambda in any proposal. I'm not saying that it isn't useful, just that
it doesn't have all the history that (non-async) lambda does, so the
argument in favour of async lambda isn't as strong. Use cases are key
- adding it "just because we can" would just make the proposal more
controversial, and then the whole thing could collapse over something
secondary.

Ultimately, this would need someone to write a PEP.

Paul
_______________________________________________
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/7WIDJHIDIQTPZNF2DCTF7D4C3UFC3XLY/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to