[Python-ideas] Re: Arrow functions polyfill

2021-03-11 Thread Rob Cliffe via Python-ideas
On 24/02/2021 14:04, Random832 wrote: On Tue, Feb 23, 2021, at 17:01, Rob Cliffe via Python-ideas wrote: As far as I know, there is no case of valid syntax using 'lambda' where replacing 'lambda' by 'def' results in valid syntax. Can anyone provide a counter-example? If not, I would support

[Python-ideas] Re: Arrow functions polyfill

2021-02-25 Thread Mike Miller
On 2021-02-25 01:05, Steven D'Aprano wrote: On Wed, Feb 24, 2021 at 06:46:21PM -0800, Mike Miller wrote: Also, I don't believe the confusion mentioned was regarding syntax, but rather a word that most people have never heard before. When I started learning Python, back when 1.5 was new and

[Python-ideas] Re: Arrow functions polyfill

2021-02-25 Thread Steven D'Aprano
On Wed, Feb 24, 2021 at 06:46:21PM -0800, Mike Miller wrote: > Also, I don't believe the confusion mentioned was regarding syntax, but > rather a word that most people have never heard before. When I started learning Python, back when 1.5 was new and cutting edge, it was an embarassingly long

[Python-ideas] Re: Arrow functions polyfill

2021-02-24 Thread Mike Miller
On 2021-02-24 06:04, Random832 wrote: I have an objection to this: "def" is short for define, and a lambda does not produce a definition. This isn't just about saving keystrokes, and even if it were, saving only three would not be worth it for a syntax that is just as confusing as the

[Python-ideas] Re: Arrow functions polyfill

2021-02-24 Thread Random832
On Tue, Feb 23, 2021, at 17:01, Rob Cliffe via Python-ideas wrote: > As far as I know, there is no case of valid syntax using 'lambda' where > replacing 'lambda' by 'def' results in valid syntax. > Can anyone provide a counter-example? > If not, I would support allowing 'def' as an alternative to

[Python-ideas] Re: Arrow functions polyfill

2021-02-23 Thread Richard Damon
On 2/23/21 5:01 PM, Rob Cliffe via Python-ideas wrote: > > > On 23/02/2021 17:46, Stéfane Fermigier wrote: >> >> >> On Tue, Feb 23, 2021 at 6:13 PM Richard Damon >> mailto:rich...@damon-family.org>> wrote: >> >> >> Also note, that I am not saying that 'arrow-functions' can't happen, >>

[Python-ideas] Re: Arrow functions polyfill

2021-02-23 Thread Rob Cliffe via Python-ideas
On 23/02/2021 17:46, Stéfane Fermigier wrote: On Tue, Feb 23, 2021 at 6:13 PM Richard Damon mailto:rich...@damon-family.org>> wrote: Also note, that I am not saying that 'arrow-functions' can't happen, just that if they are created, a natural consequence is that, like with

[Python-ideas] Re: Arrow functions polyfill

2021-02-23 Thread Barry
> On 23 Feb 2021, at 21:42, Barry wrote: > >  > > >>> On 23 Feb 2021, at 18:08, Stéfane Fermigier wrote: >>> >>  >> Both '%' and .format() support both positional and named arguments. >> >> There are probably a few use cases for .format() (vs. f-strings) but overall >> I don't believe

[Python-ideas] Re: Arrow functions polyfill

2021-02-23 Thread Barry
> On 23 Feb 2021, at 18:08, Stéfane Fermigier wrote: > >  > Both '%' and .format() support both positional and named arguments. > > There are probably a few use cases for .format() (vs. f-strings) but overall > I don't believe there is much reasons left to prefer %. I18n you can translate

[Python-ideas] Re: Arrow functions polyfill

2021-02-23 Thread Stéfane Fermigier
Both '%' and .format() support both positional and named arguments. There are probably a few use cases for .format() (vs. f-strings) but overall I don't believe there is much reasons left to prefer %. Note that the existence, and popularity, of tools like flynt and pyupgrade (that convert % and

[Python-ideas] Re: Arrow functions polyfill

2021-02-23 Thread Paul Sokolovsky
Hello, On Tue, 23 Feb 2021 12:11:00 -0500 Richard Damon wrote: [] > them. If we look at 'f-strings' as the example, I beleive f-strings > are now considered the 'preferred obvious' way to do it, when it is It's a common mistake. %-formatting was "preferred obvious" 30 years ago, and is

[Python-ideas] Re: Arrow functions polyfill

2021-02-23 Thread Stéfane Fermigier
On Tue, Feb 23, 2021 at 6:13 PM Richard Damon wrote: > > Also note, that I am not saying that 'arrow-functions' can't happen, > just that if they are created, a natural consequence is that, like with > .format(), the 'old' (lambda) way will need to be marked as 'old', and > not the current

[Python-ideas] Re: Arrow functions polyfill

2021-02-23 Thread Chris Angelico
On Wed, Feb 24, 2021 at 4:13 AM Richard Damon wrote: > As far as between % or .format(), I think the documentation is fairly > clear that the % method is 'old' and if not 'formally' deprecated, is no > longer considered the 'obvious' way to do it (even if some people will > still do it that way

[Python-ideas] Re: Arrow functions polyfill

2021-02-23 Thread Richard Damon
On 2/23/21 10:07 AM, Paul Sokolovsky wrote: > Hello, > > On Tue, 23 Feb 2021 09:35:58 -0500 > Richard Damon wrote: > > [] > >> My first thought to the idea of making an alternate syntax is the line >> from the Zen: >> >> There should be one-- and preferably only one --obvious way to do it. >>

[Python-ideas] Re: Arrow functions polyfill

2021-02-23 Thread Paul Moore
On Tue, 23 Feb 2021 at 15:52, M.-A. Lemburg wrote: > > On 23.02.2021 15:29, Paul Moore wrote: > > On Tue, 23 Feb 2021 at 14:10, M.-A. Lemburg wrote: > >> > >> The natural way in Python to write an anonymous function would > >> be to simply drop the name in a regular function definition: > >> >

[Python-ideas] Re: Arrow functions polyfill

2021-02-23 Thread M.-A. Lemburg
On 23.02.2021 15:29, Paul Moore wrote: > On Tue, 23 Feb 2021 at 14:10, M.-A. Lemburg wrote: >> >> The natural way in Python to write an anonymous function would >> be to simply drop the name in a regular function definition: >> >> def (a): return a**2 >> >> The lambda notation is less verbose and

[Python-ideas] Re: Arrow functions polyfill

2021-02-23 Thread Paul Sokolovsky
Hello, On Tue, 23 Feb 2021 09:35:58 -0500 Richard Damon wrote: [] > My first thought to the idea of making an alternate syntax is the line > from the Zen: > > There should be one-- and preferably only one --obvious way to do it. > Although that way may not be obvious at first unless you're

[Python-ideas] Re: Arrow functions polyfill

2021-02-23 Thread Richard Damon
On 2/23/21 7:57 AM, Paul Sokolovsky wrote: > Hello, > > On Tue, 23 Feb 2021 23:29:33 +1100 > Steven D'Aprano wrote: > >> On Tue, Feb 23, 2021 at 11:27:12AM +0100, Stéfane Fermigier wrote: >> >>> Also: I know there are several modern computer languages that use >>> arrows to represent anonymous

[Python-ideas] Re: Arrow functions polyfill

2021-02-23 Thread Paul Moore
On Tue, 23 Feb 2021 at 14:10, M.-A. Lemburg wrote: > > The natural way in Python to write an anonymous function would > be to simply drop the name in a regular function definition: > > def (a): return a**2 > > The lambda notation is less verbose and closer to computer > science theory, though: >

[Python-ideas] Re: Arrow functions polyfill

2021-02-23 Thread Paul Sokolovsky
Hello, On Tue, 23 Feb 2021 15:07:50 +0100 "M.-A. Lemburg" wrote: [] > FWIW: I don't understand why people are so unhappy with lambdas. I don't think that people are unhappy with lambdas. I think that people are *so* happy with lambdas, that want even shorter notation for them. > There isn't

[Python-ideas] Re: Arrow functions polyfill

2021-02-23 Thread M.-A. Lemburg
The natural way in Python to write an anonymous function would be to simply drop the name in a regular function definition: def (a): return a**2 The lambda notation is less verbose and closer to computer science theory, though: lambda a: a**2 FWIW: I don't understand why people are so unhappy

[Python-ideas] Re: Arrow functions polyfill

2021-02-23 Thread Paul Sokolovsky
Hello, On Tue, 23 Feb 2021 13:24:10 + Stestagg wrote: > I was quite feeling pretty positive about the 'stab' (thanks Steve > for this term!) operator idea, until I tried out some examples > locally, and it just feels a bit too out-of-place in python, for me > (100% subjective opinion here).

[Python-ideas] Re: Arrow functions polyfill

2021-02-23 Thread Stéfane Fermigier
On Tue, Feb 23, 2021 at 1:34 PM Steven D'Aprano wrote: > On Tue, Feb 23, 2021 at 11:27:12AM +0100, Stéfane Fermigier wrote: > > > Also: I know there are several modern computer languages that use arrows > to > > represent anonymous functions (JS, Kotlin, Scala...). > > Javascript: first release

[Python-ideas] Re: Arrow functions polyfill

2021-02-23 Thread Stestagg
I was quite feeling pretty positive about the 'stab' (thanks Steve for this term!) operator idea, until I tried out some examples locally, and it just feels a bit too out-of-place in python, for me (100% subjective opinion here). Having used stabs and compact closure syntax in various languages:

[Python-ideas] Re: Arrow functions polyfill

2021-02-23 Thread Paul Sokolovsky
Hello, On Tue, 23 Feb 2021 23:29:33 +1100 Steven D'Aprano wrote: > On Tue, Feb 23, 2021 at 11:27:12AM +0100, Stéfane Fermigier wrote: > > > Also: I know there are several modern computer languages that use > > arrows to represent anonymous functions (JS, Kotlin, Scala...). > > Javascript:

[Python-ideas] Re: Arrow functions polyfill

2021-02-23 Thread Steven D'Aprano
On Tue, Feb 23, 2021 at 11:27:12AM +0100, Stéfane Fermigier wrote: > Also: I know there are several modern computer languages that use arrows to > represent anonymous functions (JS, Kotlin, Scala...). Javascript: first release was 1995, making it 25 years old. It's older than most Javascript

[Python-ideas] Re: Arrow functions polyfill

2021-02-23 Thread Stéfane Fermigier
Also: I know there are several modern computer languages that use arrows to represent anonymous functions (JS, Kotlin, Scala...). I also personally remember using (and teaching) Maple in the mid-90s, which used arrows to define functions:

[Python-ideas] Re: Arrow functions polyfill

2021-02-23 Thread Paul Moore
On Tue, 23 Feb 2021 at 09:25, Steven D'Aprano wrote: > > On Mon, Feb 15, 2021 at 09:29:45AM -0800, Guido van Rossum wrote: > > > Proposals like this always baffle me. Python already has both anonymous and > > named functions. They are spelled with 'lambda' and 'def', respectively. > > What good

[Python-ideas] Re: Arrow functions polyfill

2021-02-23 Thread Stéfane Fermigier
Hi, My personal opinion is that arrows or even fat arrows would be a nice addition to the Python language for anonymous functions. I cringe a bit every time I have to write "lambda x: ..." (and even more for parameter-less "lambda: ..."). I have a background in math so I find arrow notation

[Python-ideas] Re: Arrow functions polyfill

2021-02-23 Thread Steven D'Aprano
On Mon, Feb 15, 2021 at 09:29:45AM -0800, Guido van Rossum wrote: > Proposals like this always baffle me. Python already has both anonymous and > named functions. They are spelled with 'lambda' and 'def', respectively. > What good would it do us to create an alternate spelling for 'def'? [...]

[Python-ideas] Re: Arrow functions polyfill

2021-02-17 Thread Chris Angelico
On Wed, Feb 17, 2021 at 9:11 PM Sven R. Kunze wrote: > Still think that "object()" should be writable since this seems like an > arbitrary restriction (+SimpleNamespace is no builtin and at least I > would use object() for fast PoCs or dirty hackery). But I guess there's > been discussion around

[Python-ideas] Re: Arrow functions polyfill

2021-02-17 Thread Sven R. Kunze
On 16.02.21 17:26, Steven D'Aprano wrote: >>> from types import SimpleNamespace >>> obj = SimpleNamespace() >>> obj.spam = 1 >>> obj namespace(spam=1) Gives you a nice repr so when you are debugging you can actually see what the object is. I see that's Python 3

[Python-ideas] Re: Arrow functions polyfill

2021-02-16 Thread Steven D'Aprano
On Tue, Feb 16, 2021 at 04:43:11PM +0100, Sven R. Kunze wrote: > >>> obj = lambda: 0 > > to define an anomyous object without the need to define a class first > (speaking of brevity). > > > "Why?", you may ask. The reason is that: > > >>> obj = object() > > does not create an instance of

[Python-ideas] Re: Arrow functions polyfill

2021-02-16 Thread Sven R. Kunze
On 15.02.21 22:42, Greg Ewing wrote: On 16/02/21 6:29 am, Guido van Rossum wrote: I can sympathize with trying to get a replacement for lambda, because many other languages have jumped on the arrow bandwagon, and few Python first-time programmers have enough of a CS background to recognize

[Python-ideas] Re: Arrow functions polyfill

2021-02-16 Thread Stephen J. Turnbull
Steven D'Aprano writes: > lambda a, b, c: a+b*c > (a, b, c) -> a+b*c Of course, the mathematicians' spelling would be (a, b, c) |-> a+b*c (Don't bother throwing things, I'm already a 5km down the road.) ___ Python-ideas mailing list --

[Python-ideas] Re: Arrow functions polyfill

2021-02-15 Thread Rob Cliffe via Python-ideas
On 15/02/2021 16:32, David Mertz wrote: On Mon, Feb 15, 2021 at 4:19 PM Guido van Rossum > wrote: Okay, here’s my dilemma. It looks like this thread wants to devise a new syntax for lambda, using e.g. (x, y) -> x+y, or the same with =>. That’s great, but

[Python-ideas] Re: Arrow functions polyfill

2021-02-15 Thread Greg Ewing
On 16/02/21 6:29 am, Guido van Rossum wrote: I can sympathize with trying to get a replacement for lambda, because many other languages have jumped on the arrow bandwagon, and few Python first-time programmers have enough of a CS background to recognize the significance of the word lambda. I

[Python-ideas] Re: Arrow functions polyfill

2021-02-15 Thread Abdulla Al Kathiri
> On 15 Feb 2021, at 9:48 PM, Ricky Teachey wrote: > > hypotenuse(x,y): (x**2+y**2)**0.5 Can I use a named function (proposed here) as an argument to a function? e.g., def example(func, x, y): return func(x, y) example(hypotenuse(x,y): (x**2+y**2)**0.5, 3, 4) Or should it be an

[Python-ideas] Re: Arrow functions polyfill

2021-02-15 Thread Paul Sokolovsky
Hello, On Mon, 15 Feb 2021 13:00:50 -0500 Ricky Teachey wrote: > On Mon, Feb 15, 2021 at 12:55 PM David Mertz wrote: > > > On Mon, Feb 15, 2021, 12:26 PM Ricky Teachey > > > >> f(x,y)=>x,y->str > >>> > >> > > I read this as "my cat walked across my keyboard, and I'm very > > proud she

[Python-ideas] Re: Arrow functions polyfill

2021-02-15 Thread Ricky Teachey
On Mon, Feb 15, 2021 at 12:55 PM David Mertz wrote: > On Mon, Feb 15, 2021, 12:26 PM Ricky Teachey > >> f(x,y)=>x,y->str >>> >> > I read this as "my cat walked across my keyboard, and I'm very proud she > wants to be a programmer." > Our cat died last fall so if that's what happened, I should

[Python-ideas] Re: Arrow functions polyfill

2021-02-15 Thread David Mertz
On Mon, Feb 15, 2021, 12:26 PM Ricky Teachey > f(x,y)=>x,y->str >> > I read this as "my cat walked across my keyboard, and I'm very proud she wants to be a programmer." > ___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an

[Python-ideas] Re: Arrow functions polyfill

2021-02-15 Thread Ricky Teachey
On Mon, Feb 15, 2021 at 12:30 PM Guido van Rossum wrote: > On Mon, Feb 15, 2021 at 9:02 AM Ricky Teachey wrote: > >> [...] >> But if we could expand the proposal to allow both anonymous and named >> functions, that would seem like a fantastic idea to me. >> >> Anonymous function syntax: >> >>

[Python-ideas] Re: Arrow functions polyfill

2021-02-15 Thread Jonathan Goble
On Mon, Feb 15, 2021 at 12:29 PM Ricky Teachey wrote: > f(x,y)=>x+y->str > I can't -1 this enough. How do I read this? Imagine you have never seen this discussion and you come across this code in the wild. You are familiar with type hints, including return type annotations, but aren't familiar

[Python-ideas] Re: Arrow functions polyfill

2021-02-15 Thread Guido van Rossum
On Mon, Feb 15, 2021 at 9:02 AM Ricky Teachey wrote: > [...] > But if we could expand the proposal to allow both anonymous and named > functions, that would seem like a fantastic idea to me. > > Anonymous function syntax: > > (x,y)->x+y > > Named function syntax: > > f(x,y)->x+y > Proposals

[Python-ideas] Re: Arrow functions polyfill

2021-02-15 Thread Ricky Teachey
On Mon, Feb 15, 2021 at 12:02 PM Ricky Teachey wrote: > On Mon, Feb 15, 2021, 11:34 AM David Mertz wrote: > >> On Mon, Feb 15, 2021 at 4:19 PM Guido van Rossum >> wrote: >> >>> Okay, here’s my dilemma. It looks like this thread wants to devise a new >>> syntax for lambda, using e.g. (x, y) ->

[Python-ideas] Re: Arrow functions polyfill

2021-02-15 Thread Ricky Teachey
On Mon, Feb 15, 2021, 11:34 AM David Mertz wrote: > On Mon, Feb 15, 2021 at 4:19 PM Guido van Rossum wrote: > >> Okay, here’s my dilemma. It looks like this thread wants to devise a new >> syntax for lambda, using e.g. (x, y) -> x+y, or the same with =>. That’s >> great, but doesn’t open new

[Python-ideas] Re: Arrow functions polyfill

2021-02-15 Thread David Mertz
On Mon, Feb 15, 2021 at 4:19 PM Guido van Rossum wrote: > Okay, here’s my dilemma. It looks like this thread wants to devise a new > syntax for lambda, using e.g. (x, y) -> x+y, or the same with =>. That’s > great, but doesn’t open new vistas. OTOH, for people using type > annotations, a much

[Python-ideas] Re: Arrow functions polyfill

2021-02-15 Thread Guido van Rossum
Okay, here’s my dilemma. It looks like this thread wants to devise a new syntax for lambda, using e.g. (x, y) -> x+y, or the same with =>. That’s great, but doesn’t open new vistas. OTOH, for people using type annotations, a much more pressing issue is an alternative for typing.Callable that is

[Python-ideas] Re: Arrow functions polyfill

2021-02-15 Thread Steven D'Aprano
On Mon, Feb 15, 2021 at 02:12:03AM +1100, Chris Angelico wrote: > On Sun, Feb 14, 2021 at 8:42 PM Steven D'Aprano wrote: > > We should not choose the more confusing, error-prone solution out of > > fear of being different. Python is already different from Javascript in > > every regard: > > > >

[Python-ideas] Re: Arrow functions polyfill

2021-02-14 Thread Chris Angelico
On Mon, Feb 15, 2021 at 5:28 PM Steven D'Aprano wrote: > In the first case, => will forever be fighting against the much stronger > memory trace of >= (I think we can agree that comparisons will be more > common than anonymous functions). People's muscle-memory will type >= > when they want the

[Python-ideas] Re: Arrow functions polyfill

2021-02-14 Thread Steven D'Aprano
On Sun, Feb 14, 2021 at 01:31:29AM -0500, Random832 wrote: > > http://www.rosettacode.org/wiki/Function_definition > > That page doesn't really do well at explaining lambda expressions > specifically, omitting it for some languages that definitely have them > [such as Dart]. It's a community

[Python-ideas] Re: Arrow functions polyfill

2021-02-14 Thread Brendan Barnwell
On 2021-02-14 00:54, Paul Sokolovsky wrote: There're 2 things about that from an experienced JavaScript-hater (but a pragmatic guy otherwise): 1. We aren't talking about all of JavaScript, but a recent features added to JS. 2. JS has real money being poured into it, and no longer designed on

[Python-ideas] Re: Arrow functions polyfill

2021-02-14 Thread Chris Angelico
On Sun, Feb 14, 2021 at 8:42 PM Steven D'Aprano wrote: > We should not choose the more confusing, error-prone solution out of > fear of being different. Python is already different from Javascript in > every regard: > Is it really? > - the basic execution model is different; Don't know what you

[Python-ideas] Re: Arrow functions polyfill

2021-02-14 Thread Steven D'Aprano
On Sun, Feb 14, 2021 at 11:54:21AM +0300, Paul Sokolovsky wrote: > > > b) Python already uses "->" for function return *type*. And there's > > > idea to generalize it to *function type* in general. E.g. a function > > > "(a, b) => a + b" can have type "(int, int) -> int". > > > > This supports

[Python-ideas] Re: Arrow functions polyfill

2021-02-14 Thread Paul Sokolovsky
Hello, On Sun, 14 Feb 2021 13:57:14 +1100 Steven D'Aprano wrote: > On Sun, Feb 14, 2021 at 12:47:30AM +0300, Paul Sokolovsky wrote: > > Hello, > > > > On Sat, 13 Feb 2021 16:25:24 -0500 > > Cade Brown wrote: > > > > > In my humble opinion, arrows should be '->' instead of '=>'. It > > >

[Python-ideas] Re: Arrow functions polyfill

2021-02-13 Thread Random832
On Sat, Feb 13, 2021, at 21:57, Steven D'Aprano wrote: > # Erlang > multiply(X,Y) -> X * Y. For the record, Erlang's lambda syntax is the relatively unpleasant "fun(X,Y) -> X * Y end". Elixir is the same, except that the keyword is fn. > Dart uses "=>" > > multiply(x, y) => x * y;

[Python-ideas] Re: Arrow functions polyfill

2021-02-13 Thread Steven D'Aprano
On Sun, Feb 14, 2021 at 12:47:30AM +0300, Paul Sokolovsky wrote: > Hello, > > On Sat, 13 Feb 2021 16:25:24 -0500 > Cade Brown wrote: > > > In my humble opinion, arrows should be '->' instead of '=>'. It always > > annoys me when languages use that symbol > > That's unlikely, as was discussed

[Python-ideas] Re: Arrow functions polyfill

2021-02-13 Thread Cade Brown
It's not my call in Python so I can't demand one way or another. I was just saying that it makes less sense and has always been less readable for me and most developers I've talked to, as it resembles a comparison operator. Also, mathematically, mappings are typically written with a skinny arrow,

[Python-ideas] Re: Arrow functions polyfill

2021-02-13 Thread Paul Sokolovsky
Hello, On Sat, 13 Feb 2021 16:25:24 -0500 Cade Brown wrote: > In my humble opinion, arrows should be '->' instead of '=>'. It always > annoys me when languages use that symbol That's unlikely, as was discussed in this thread previously: a) JavaScript already uses "=>", and it doesn't make

[Python-ideas] Re: Arrow functions polyfill

2021-02-13 Thread Cade Brown
In my humble opinion, arrows should be '->' instead of '=>'. It always annoys me when languages use that symbol On Sat, Feb 13, 2021, 14:52 Paul Sokolovsky wrote: > Hello, > > On Sat, 13 Feb 2021 09:24:51 -0800 > Matthias Bussonnier wrote: > > > Works well with 0 parameters and currying, read

[Python-ideas] Re: Arrow functions polyfill

2021-02-13 Thread Paul Sokolovsky
Hello, On Sat, 13 Feb 2021 09:24:51 -0800 Matthias Bussonnier wrote: > Works well with 0 parameters and currying, read almost like a haskell > function definition. > > f = () => ((b) => b) > g = (a) => (b) => b+a > h = (a) => (b) => (b, a) > i = (a,b) => a > > print(f()(2)) >

[Python-ideas] Re: Arrow functions polyfill

2021-02-13 Thread Matthias Bussonnier
Works well with 0 parameters and currying, read almost like a haskell function definition. f = () => ((b) => b) g = (a) => (b) => b+a h = (a) => (b) => (b, a) i = (a,b) => a print(f()(2)) print(g(1)(2)) print(h(1)(2)) print(i(1, 2)) On Sat, 13 Feb 2021 at 06:35, Paul Sokolovsky wrote: > >