[Python-ideas] Re: Alternate lambda syntax

2021-02-23 Thread Steven D'Aprano
On Fri, Feb 19, 2021 at 07:35:19PM +0300, Paul Sokolovsky wrote: > People won't learn "two syntaxes for Callable". People shun using > Python's current type annotations due to their ugliness and "quick hack > without thinking of UX" feel. Only after there will be "int | str" > instead of "Union[in

[Python-ideas] Re: Alternate lambda syntax

2021-02-23 Thread Caleb Donovick
I was +0.5 on the arrow syntax for `Callable`. It seemed like a nice short hand but understood the arguments against it in the vain of "There should be one-- and preferably only one --obvious way to do it." But > The latter is the same as the former, just in the AST form. That's what > we ask p

[Python-ideas] Re: Alternate lambda syntax

2021-02-19 Thread Paul Sokolovsky
Hello, On Sat, 20 Feb 2021 00:23:13 +0900 "Stephen J. Turnbull" wrote: > Abdulla Al Kathiri writes: > > Condensing to the parts which are in question, > > > def test(self, func: t.Callable[..., bool], *args, **kwargs) -> > > Predicate: return self._build_predicate( > >lamb

[Python-ideas] Re: Alternate lambda syntax

2021-02-19 Thread Stephen J. Turnbull
Abdulla Al Kathiri writes: Condensing to the parts which are in question, > def test(self, func: t.Callable[..., bool], *args, **kwargs) -> Predicate: > return self._build_predicate( >lambda lhs, value: func(lhs, *args, **kwargs), > Operation.TEST, >

[Python-ideas] Re: Alternate lambda syntax

2021-02-18 Thread Abdulla Al Kathiri
def test(self, func: t.Callable[..., bool], *args, **kwargs) -> Predicate: """ Run a user-defined test function against the value. >>> def test_func(val): ... return val == 42 ... >>> var('f1').test(test_func) :param func: The function

[Python-ideas] Re: Alternate lambda syntax

2021-02-18 Thread Stephen J. Turnbull
2qdxy4rzwzuui...@potatochowder.com writes: > On 2021-02-18 at 18:10:16 +0400, > Abdulla Al Kathiri wrote: > > > I will be very happy if those versions of Callable and anonymous > > functions exist in Python right now. See how elegant that would look > > like.. > > > > def func(x: int, y:

[Python-ideas] Re: Alternate lambda syntax

2021-02-18 Thread Greg Ewing
On 19/02/21 9:43 am, Steven D'Aprano wrote: Although I have heard from Ruby enthusiasts that the ability to write large, complex, multi-statement anonymous block functions is really useful, its not something I can personally say I have missed. Ruby may be somewhat different here, because Ruby's

[Python-ideas] Re: Alternate lambda syntax

2021-02-18 Thread David Mertz
On Thu, Feb 18, 2021 at 8:46 PM Steven D'Aprano wrote: > Although I have heard from Ruby enthusiasts that the ability to write > large, complex, multi-statement anonymous block functions is really > useful, its not something I can personally say I have missed. > I think that once you get past a f

[Python-ideas] Re: Alternate lambda syntax

2021-02-18 Thread Steven D'Aprano
On Wed, Feb 17, 2021 at 07:03:55PM +, Gustavo Carneiro wrote: > Just my 2c, I don't find lambda verbose at all, quite like it. > > But I wish Python allowed for multi-line lambda functions... somehow. Python allows for multi-*line* lambda: lambda key, value, condition, sep='', default

[Python-ideas] Re: Alternate lambda syntax

2021-02-18 Thread 2QdxY4RzWzUUiLuE
On 2021-02-18 at 18:10:16 +0400, Abdulla Al Kathiri wrote: > I will be very happy if those versions of Callable and anonymous > functions exist in Python right now. See how elegant that would look > like.. > > def func(x: int, y: int, f: (int, int) -> int) -> int: > return f(x, y) Elegan

[Python-ideas] Re: Alternate lambda syntax

2021-02-18 Thread Abdulla Al Kathiri
I will be very happy if those versions of Callable and anonymous functions exist in Python right now. See how elegant that would look like.. def func(x: int, y: int, f: (int, int) -> int) -> int: return f(x, y) print(func(3, 4, (x, y) => x + y)) #Out: 7 Imagine your mouse is on :func

[Python-ideas] Re: Alternate lambda syntax

2021-02-18 Thread Paul Sokolovsky
Hello, On Wed, 17 Feb 2021 18:43:09 -0300 "Joao S. O. Bueno" wrote: > On Wed, 17 Feb 2021 at 18:15, Abdulla Al Kathiri < > alkathiri.abdu...@gmail.com> wrote: > > > How is this not pythonic? > > > > series.apply(x -> x**2) > > Compared to.. > > series.apply(lambda x: x**2) > > > > > > (x, y)

[Python-ideas] Re: Alternate lambda syntax

2021-02-17 Thread Stephen J. Turnbull
Abdulla Al Kathiri writes: > How is this not pythonic? > > series.apply(x -> x**2) > Compared to.. > series.apply(lambda x: x**2) The main problem is that the second already exists, and the first doesn't, while the first adds no new power to the language, and isn't enough more readable (a

[Python-ideas] Re: Alternate lambda syntax

2021-02-17 Thread Greg Ewing
On 18/02/21 3:38 am, MRAB wrote: So a "byte" is part of a word (a word contains multiple characters). In the Burroughs B6900 architecture, programs consisted of 48-bit words broken up into 8-bit opcodes called "syllables". -- Greg ___ Python-ideas m

[Python-ideas] Re: Alternate lambda syntax

2021-02-17 Thread Abdulla Al Kathiri
Those are not anonymous functions though. > On 18 Feb 2021, at 1:43 AM, Joao S. O. Bueno wrote: > > def f1(x, y): >return x + y > > def f2(): > return 0 > > def f3(x): >return x ** 2 > ___ Python-ideas mailing list -- python-ideas@pytho

[Python-ideas] Re: Alternate lambda syntax

2021-02-17 Thread Joao S. O. Bueno
On Wed, 17 Feb 2021 at 18:15, Abdulla Al Kathiri < alkathiri.abdu...@gmail.com> wrote: > How is this not pythonic? > > series.apply(x -> x**2) > Compared to.. > series.apply(lambda x: x**2) > > > (x, y) -> x+y, () -> 0, (x) -> x**2 (for single parameter, we can write it > without parenthesis like

[Python-ideas] Re: Alternate lambda syntax

2021-02-17 Thread Abdulla Al Kathiri
How is this not pythonic? series.apply(x -> x**2) Compared to.. series.apply(lambda x: x**2) (x, y) -> x+y, () -> 0, (x) -> x**2 (for single parameter, we can write it without parenthesis like the example above) are pythonic enough to my eyes. Abdulla > On 17 Feb 2021, at 10:59 PM, Joao S.

[Python-ideas] Re: Alternate lambda syntax

2021-02-17 Thread Gustavo Carneiro
On Wed, 17 Feb 2021 at 18:30, Ethan Furman wrote: > On 2/17/21 8:47 AM, Random832 wrote: > > On Tue, Feb 16, 2021, at 23:24, Stephen J. Turnbull wrote: > > >> except a couple of characters. So what currently looks like > >> > >> some_list.sort(key=lambda e: e[3].priority) > >> > >> would th

[Python-ideas] Re: Alternate lambda syntax

2021-02-17 Thread Joao S. O. Bueno
On Wed, 17 Feb 2021 at 15:31, Ethan Furman wrote: > On 2/17/21 8:47 AM, Random832 wrote: > > On Tue, Feb 16, 2021, at 23:24, Stephen J. Turnbull wrote: > > >> except a couple of characters. So what currently looks like > >> > >> some_list.sort(key=lambda e: e[3].priority) > >> > >> would th

[Python-ideas] Re: Alternate lambda syntax

2021-02-17 Thread Ethan Furman
On 2/17/21 8:47 AM, Random832 wrote: On Tue, Feb 16, 2021, at 23:24, Stephen J. Turnbull wrote: except a couple of characters. So what currently looks like some_list.sort(key=lambda e: e[3].priority) would then be some_list.sort(key=(e)->e[3].priority) Let's not pretend the key

[Python-ideas] Re: Alternate lambda syntax

2021-02-17 Thread Random832
On Tue, Feb 16, 2021, at 23:24, Stephen J. Turnbull wrote: > except a couple of characters. So what currently looks like > > some_list.sort(key=lambda e: e[3].priority) > > would then be > > some_list.sort(key=(e)->e[3].priority) Let's not pretend the key argument being keyword-only is

[Python-ideas] Re: Alternate lambda syntax

2021-02-17 Thread MRAB
On 2021-02-17 05:57, Steven D'Aprano wrote: On Wed, Feb 17, 2021 at 11:13:08AM +1300, Greg Ewing wrote: On 17/02/21 7:10 am, Steven D'Aprano wrote: >"It's Greek letter, like pi that you may remember from maths >class. In some technical computer science, the Greek L, lambda, is used >as the symbo

[Python-ideas] Re: Alternate lambda syntax

2021-02-16 Thread Steven D'Aprano
On Wed, Feb 17, 2021 at 11:13:08AM +1300, Greg Ewing wrote: > On 17/02/21 7:10 am, Steven D'Aprano wrote: > >"It's Greek letter, like pi that you may remember from maths > >class. In some technical computer science, the Greek L, lambda, is used > >as the symbol for functions." > > The most accurat

[Python-ideas] Re: Alternate lambda syntax

2021-02-16 Thread Stephen J. Turnbull
Ned Batchelder writes: > "lambda" is unnecessarily obscure. And it should be. It's really only useful as an argument. There's no advantage to foo = (x) -> 1 vs. def foo(x): return 1 except a couple of characters. So what currently looks like some_list.sort(key=lambda e: e[3].

[Python-ideas] Re: Alternate lambda syntax

2021-02-16 Thread M.-A. Lemburg
On 16.02.2021 23:13, Greg Ewing wrote: > On 17/02/21 7:10 am, Steven D'Aprano wrote: >> "It's Greek letter, like pi that you may remember from maths >> class. In some technical computer science, the Greek L, lambda, is used >> as the symbol for functions." > > The most accurate answer seems to be

[Python-ideas] Re: Alternate lambda syntax

2021-02-16 Thread Steven D'Aprano
On Wed, Feb 17, 2021 at 01:03:40AM +0400, Abdulla Al Kathiri wrote: > From Wikipedia: > "The term originated as an abstraction of the sequence: single, > couple/double, triple, quadruple, quintuple, sextuple, septuple, > octuple, ..., n‑tuple, …" And that's so obvious in hindsight. Thank you.

[Python-ideas] Re: Alternate lambda syntax

2021-02-16 Thread Greg Ewing
On 17/02/21 7:10 am, Steven D'Aprano wrote: Its no more "magic" than tuple, deque, iterator, coroutine, ordinal, modulus, etc, not to mention those ordinary English words with specialised jargon meanings like float, tab, zip, thread, key, promise, trampoline, tree, hash etc. Actually, I think i

[Python-ideas] Re: Alternate lambda syntax

2021-02-16 Thread Greg Ewing
On 17/02/21 7:10 am, Steven D'Aprano wrote: "It's Greek letter, like pi that you may remember from maths class. In some technical computer science, the Greek L, lambda, is used as the symbol for functions." The most accurate answer seems to be "Because somebody made a mistake transcribing a mat

[Python-ideas] Re: Alternate lambda syntax

2021-02-16 Thread Abdulla Al Kathiri
From Wikipedia: "The term originated as an abstraction of the sequence: single, couple/double, triple, quadruple, quintuple, sextuple, septuple, octuple, ..., n‑tuple, …" > On 16 Feb 2021, at 10:10 PM, Steven D'Aprano wrote: > > And I still > don't know where the word comes from in the first p

[Python-ideas] Re: Alternate lambda syntax

2021-02-16 Thread Steven D'Aprano
On Tue, Feb 16, 2021 at 11:38:33AM -0500, Ned Batchelder wrote: > "lambda" is unnecessarily obscure. > > Beginner: "why is it called lambda?" > > Teacher: "Don't worry about it, just use it to define a function" That's a bad answer. A better answer that is more appropriate for nearly everyone

[Python-ideas] Re: Alternate lambda syntax

2021-02-16 Thread Paul Moore
On Tue, 16 Feb 2021 at 16:40, Ned Batchelder wrote: > > "lambda" is unnecessarily obscure. > > Beginner: "why is it called lambda?" > > Teacher: "Don't worry about it, just use it to define a function" > > I'm not taking a side on whether to change Python, but let's please not > lose sight of just

[Python-ideas] Re: Alternate lambda syntax

2021-02-16 Thread Ned Batchelder
"lambda" is unnecessarily obscure. Beginner: "why is it called lambda?" Teacher: "Don't worry about it, just use it to define a function" I'm not taking a side on whether to change Python, but let's please not lose sight of just how opaque the word "lambda" is. People who know the background

[Python-ideas] Re: Alternate lambda syntax

2021-02-16 Thread Rob Cliffe via Python-ideas
On 15/02/2021 19:47, Mike Miller wrote: On 2021-02-13 14:33, Christopher Barker wrote: On Fri, Feb 12, 2021 at 1:00 AM Brendan Barnwell mailto:brenb...@brenbarn.net>> wrote:         The only thing that would be better than lambda is a less confusing     keyword. There seems to be a fre

[Python-ideas] Re: Alternate lambda syntax

2021-02-15 Thread Mike Miller
On 2021-02-13 14:33, Christopher Barker wrote: On Fri, Feb 12, 2021 at 1:00 AM Brendan Barnwell > wrote:         The only thing that would be better than lambda is a less confusing keyword. There seems to be a frequent objection to the word "lambda" -- pe

[Python-ideas] Re: Alternate lambda syntax

2021-02-14 Thread Christopher Barker
On Sun, Feb 14, 2021 at 4:26 AM Serhiy Storchaka wrote: > Lambda is a questionable feature at all. With support of comprehensions, > local functions, the operator and functools modules there are not many > use cases for lambda expression. They are supported, well, but it is not > significant part

[Python-ideas] Re: Alternate lambda syntax

2021-02-14 Thread Paul Sokolovsky
Hello, On Sat, 13 Feb 2021 14:33:43 -0800 Christopher Barker wrote: > There seems to be a frequent objection to the word "lambda" -- > personally, I found it cryptic, but it's not hard to remember, and it > IS easy to look up. There seems to be a bit too many posts downputting the "lambda" keyw

[Python-ideas] Re: Alternate lambda syntax

2021-02-14 Thread Steven D'Aprano
Be bold, they say... On Mon, Feb 15, 2021 at 02:13:38AM +1100, Steven D'Aprano wrote: > If I'm wrong, I'm sure somebody will point that out. I'm not frightened > of making bold claims that turn out to be wrong: that just means I have > learned something new. (Or something old that I forgot.)

[Python-ideas] Re: Alternate lambda syntax

2021-02-14 Thread Steven D'Aprano
On Sun, Feb 14, 2021 at 11:23:59AM +0300, Paul Sokolovsky wrote: > > We've seen Paul mistake => for >= and he's not the only one. > > Well, my mistake is based on the fact that I don't spend high-level > neurons on remembering mundane low-level things, like order of > characters if the "greater o

[Python-ideas] Re: Alternate lambda syntax

2021-02-14 Thread Abdulla Al Kathiri
def func(x: int, y: int, f: (int, int) -> int) -> int: return f(x, y) print(func(1, 4, (x, y) -> x + y)) #Output: 5 I think we can still use the same syntax for both typing.Callable and lambda. It would act like Callable if it comes after the “:” in annotations or after the “-

[Python-ideas] Re: Alternate lambda syntax

2021-02-14 Thread Serhiy Storchaka
11.02.21 13:24, J. Pic пише: > 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) This syntax is ambiguous. if (y): len(y): What does the first colon mean? You cannot say until you read the

[Python-ideas] Re: Alternate lambda syntax

2021-02-14 Thread anthony.flury via Python-ideas
On 12/02/2021 07:32, Paul Sokolovsky wrote: Hello, On Fri, 12 Feb 2021 18:26:53 +1100 Chris Angelico wrote: On Fri, Feb 12, 2021 at 6:24 PM Paul Sokolovsky wrote: ... And on the 2nd thought, that won't work. The reason it works in JS is that it doesn't have tuples. In Python, "(a, b) => (

[Python-ideas] Re: Alternate lambda syntax

2021-02-14 Thread Paul Sokolovsky
Hello, On Sun, 14 Feb 2021 18:36:14 +1100 Steven D'Aprano wrote: > On Thu, Feb 11, 2021 at 09:36:25PM -0800, Guido van Rossum wrote: > > > Agreed. I'd prefer the JavaScript solution, since -> already has a > > different meaning in Python return *type*. We could use -> to > > simplify typing.Cal

[Python-ideas] Re: Alternate lambda syntax

2021-02-13 Thread Steven D'Aprano
On Thu, Feb 11, 2021 at 09:36:25PM -0800, Guido van Rossum wrote: > Agreed. I'd prefer the JavaScript solution, since -> already has a > different meaning in Python return *type*. We could use -> to simplify > typing.Callable, and => to simplify lambda. Please no! That will lead to constant confu

[Python-ideas] Re: Alternate lambda syntax

2021-02-13 Thread Chris Angelico
On Sun, Feb 14, 2021 at 9:33 AM Christopher Barker wrote: > > On Fri, Feb 12, 2021 at 1:00 AM Brendan Barnwell > wrote: >> >> >> The only thing that would be better than lambda is a less confusing >> keyword. > > > Is this really what this is all about? removing that word? I do think tha

[Python-ideas] Re: Alternate lambda syntax

2021-02-13 Thread Christopher Barker
On Fri, Feb 12, 2021 at 1:00 AM Brendan Barnwell wrote: > > The only thing that would be better than lambda is a less > confusing > keyword. Is this really what this is all about? removing that word? I do think that adding a parens around the parameters would make it a bit more clear, b

[Python-ideas] Re: Alternate lambda syntax

2021-02-13 Thread Brendan Barnwell
On 2021-02-12 03:18, Chris Angelico wrote: On Fri, Feb 12, 2021 at 7:57 PM Brendan Barnwell 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

[Python-ideas] Re: Alternate lambda syntax

2021-02-12 Thread Andy Challis
Did you mean this Paul? (a, b) >= (1, 2) ___ 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://m

[Python-ideas] Re: Alternate lambda syntax

2021-02-12 Thread Paul Moore
Fair enough. Whoever writes a PEP for this will need to do the relevant research and present the arguments in detail. But until someone's ready to write that PEP, we can continue discussing on the assumption that if someone finds the async version useful, they'll speak up. Paul On Fri, 12 Feb 202

[Python-ideas] Re: Alternate lambda syntax

2021-02-12 Thread Abdulla Al Kathiri
I am not that familiar with asyncio either. I only wrote a few utility scripts that runs concurrent subprocesses mixed with some blocking functions running in concurrent.ProcessPoolExecutor pool (using asyncio.run_in_executor). That is all what I did with regard asyncio. Your function f2 and my

[Python-ideas] Re: Alternate lambda syntax

2021-02-12 Thread Chris Angelico
On Fri, Feb 12, 2021 at 7:57 PM Brendan Barnwell 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 a

[Python-ideas] Re: Alternate lambda syntax

2021-02-12 Thread Paul Moore
On Fri, 12 Feb 2021 at 09:26, Abdulla Al Kathiri 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

[Python-ideas] Re: Alternate lambda syntax

2021-02-12 Thread Abdulla Al Kathiri
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” im

[Python-ideas] Re: Alternate lambda syntax

2021-02-12 Thread Brendan Barnwell
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 eve

[Python-ideas] Re: Alternate lambda syntax

2021-02-11 Thread Paul Sokolovsky
Hello, On Fri, 12 Feb 2021 18:26:53 +1100 Chris Angelico wrote: > On Fri, Feb 12, 2021 at 6:24 PM Paul Sokolovsky > wrote: > > ... And on the 2nd thought, that won't work. The reason it works in > > JS is that it doesn't have tuples. In Python, "(a, b) => (1, 2)" > > means "compare a tuple for

[Python-ideas] Re: Alternate lambda syntax

2021-02-11 Thread Random832
On Fri, Feb 12, 2021, at 02:23, Paul Sokolovsky wrote: > > Great to hear there's no desire to stray away from JavaScript just for > > the purpose of being different. > > ... And on the 2nd thought, that won't work. The reason it works in JS > is that it doesn't have tuples. In Python, "(a, b) => (

[Python-ideas] Re: Alternate lambda syntax

2021-02-11 Thread Chris Angelico
On Fri, Feb 12, 2021 at 6:24 PM Paul Sokolovsky wrote: > ... And on the 2nd thought, that won't work. The reason it works in JS > is that it doesn't have tuples. In Python, "(a, b) => (1, 2)" means > "compare a tuple for greater-or-equal". Should be safe actually - "=>" is not a valid comparison

[Python-ideas] Re: Alternate lambda syntax

2021-02-11 Thread Paul Sokolovsky
Hello, On Fri, 12 Feb 2021 09:55:16 +0300 Paul Sokolovsky wrote: > Hello, > > On Thu, 11 Feb 2021 21:36:25 -0800 > Guido van Rossum wrote: > > > > but I think it'd probably be > > > better to use similar syntax to C#, Java, and Javascript instead, > > > and use () -> [12] or () => 12... > > >

[Python-ideas] Re: Alternate lambda syntax

2021-02-11 Thread Paul Sokolovsky
Hello, On Thu, 11 Feb 2021 21:36:25 -0800 Guido van Rossum wrote: > > but I think it'd probably be > > better to use similar syntax to C#, Java, and Javascript instead, > > and use () -> [12] or () => 12... > > > > Agreed. I'd prefer the JavaScript solution, since -> already has a > different

[Python-ideas] Re: Alternate lambda syntax

2021-02-11 Thread Paul Sokolovsky
Hello, On Thu, 11 Feb 2021 23:57:16 -0500 Random832 wrote: [] > > > I'd like to propose the following: > > > > > > w = (): [12] > > > > What will be the meaning of {(): [12]} ? Hint: it will be a > > dictionary of empty tuple mapping to a list, where do you see > > lambda here? > > This

[Python-ideas] Re: Alternate lambda syntax

2021-02-11 Thread Guido van Rossum
On Thu, Feb 11, 2021 at 8:58 PM Random832 wrote: > On Thu, Feb 11, 2021, at 06:48, Paul Sokolovsky wrote: > > Hello, > > > > On Thu, 11 Feb 2021 12:24:55 +0100 > > "J. Pic" wrote: > > > > > Hi all, > > > > > > Lambdas can be defined as such: > > > > > > w = lambda: [12] > > > x = lambda y: len(y

[Python-ideas] Re: Alternate lambda syntax

2021-02-11 Thread Random832
On Thu, Feb 11, 2021, at 06:48, Paul Sokolovsky wrote: > Hello, > > On Thu, 11 Feb 2021 12:24:55 +0100 > "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] >

[Python-ideas] Re: Alternate lambda syntax

2021-02-11 Thread Paul Moore
On Thu, 11 Feb 2021 at 15:09, J. Pic wrote: > > I think you also need return, and double space pound space qa to pass linters: > > def foo(): return 1 # noqa > > Instead of > > foo = lambda: 1 > > And this proposal: > > foo(): 1 > > The benefit is just to get more out of the 80 characters when we

[Python-ideas] Re: Alternate lambda syntax

2021-02-11 Thread J. Pic
I think you also need return, and double space pound space qa to pass linters: def foo(): return 1 # noqa Instead of foo = lambda: 1 And this proposal: foo(): 1 The benefit is just to get more out of the 80 characters when we want to define a short callback. I understand this is not a life c

[Python-ideas] Re: Alternate lambda syntax

2021-02-11 Thread Steven D'Aprano
On Thu, Feb 11, 2021 at 12:42:39PM +0100, J. Pic wrote: > foo(x): len(x) > > Would be equivalent to: > > foo = lambda x: len(x) > > Would that work? The question is not whether it would work, but whether it would be a good idea. What benefit does it give? Just write: def foo(x): return

[Python-ideas] Re: Alternate lambda syntax

2021-02-11 Thread J. Pic
Oh, I didn't think of it, thank you Paul. Inspiration from JavaScript was not a good idea. Instead, would like to propose to make the "def" keyword optional like in bash: foo(x): len(x) Would be equivalent to: foo = lambda x: len(x) Would that work? On Thu, Feb 11, 2021 at 12:24 PM J. Pic wr

[Python-ideas] Re: Alternate lambda syntax

2021-02-11 Thread Paul Sokolovsky
Hello, On Thu, 11 Feb 2021 12:24:55 +0100 "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] What will be the meaning of {(): [12]} ? Hint: it will be a dictionary of empty tuple m