Re: [Python-ideas] Why operators are useful

2019-03-19 Thread Greg Ewing
Antoine Pitrou wrote: You are being idealistic here. MyPy relies on typing hints being available, and sufficiently precise. Yes, but it doesn't require type hints for *everything*. Given enough starting points, it can figure out the rest. Mathematicians rely heavily on their readers being

Re: [Python-ideas] Why operators are useful

2019-03-19 Thread Antoine Pitrou
On Tue, 19 Mar 2019 10:49:41 +1300 Greg Ewing wrote: > Rémi Lapeyre wrote: > > > You can make "inferences from the way things are used". But the > > comparison with maths stops here, you don’t make such inferences because > > your > > object must be well defined before you start using it. >

Re: [Python-ideas] Why operators are useful

2019-03-18 Thread Dan Sommers
On 3/18/19 7:12 PM, Steven D'Aprano wrote: > On Mon, Mar 18, 2019 at 06:34:48PM -0500, Dan Sommers wrote: > >> So how many of you got tired of those three statements and >> added something like the following function to your private >> collection of useful functions: >> >> def

Re: [Python-ideas] Why operators are useful

2019-03-18 Thread Steven D'Aprano
On Mon, Mar 18, 2019 at 06:34:48PM -0500, Dan Sommers wrote: > So how many of you got tired of those three statements and > added something like the following function to your private > collection of useful functions: > > def merged_mappings(mapping, other): > temp = mapping.copy() >

Re: [Python-ideas] Why operators are useful

2019-03-18 Thread Steven D'Aprano
On Mon, Mar 18, 2019 at 05:51:08AM -0700, Rémi Lapeyre wrote: > Maths’ typing is explicit so you don’t need to spend brain cycles to > determine them. Surely that depends on how formal you are being? Maths can vary hugely in formality, even at a professional level. It is a terrible

Re: [Python-ideas] Why operators are useful

2019-03-18 Thread Dan Sommers
On 3/18/19 6:08 PM, Steven D'Aprano wrote: On Mon, Mar 18, 2019 at 03:12:52PM +0100, Antoine Pitrou wrote: (also, don't forget you can still use the copy() + update() method) If we had fluent method calls, we could write: process(mapping.copy().update(other)) but we don't, so we use a

Re: [Python-ideas] Why operators are useful

2019-03-18 Thread Steven D'Aprano
On Sat, Mar 16, 2019 at 07:13:04PM -0400, Terry Reedy wrote: > >     new = a.copy() > >     new.update(b) > >     # do something with new > > In my census of the stdlib, already posted and noted as subject to > error, this was twice as common as all other non-update-in-place >

Re: [Python-ideas] Why operators are useful

2019-03-18 Thread Steven D'Aprano
On Mon, Mar 18, 2019 at 04:07:11PM +0100, Jimmy Girardet wrote: > The syntax {**b,**c} wasn't hard to remember. [...] > And easy because at the end it's idiomatic. It is only idiomatic if moderately experienced Python programmers can automatically read it and write it without thinking about

Re: [Python-ideas] Why operators are useful

2019-03-18 Thread Steven D'Aprano
On Mon, Mar 18, 2019 at 03:12:52PM +0100, Antoine Pitrou wrote: > (also, don't forget you can still use the copy() + update() method) If we had fluent method calls, we could write: process(mapping.copy().update(other)) but we don't, so we use a pointless temporary variable: temp =

Re: [Python-ideas] Why operators are useful

2019-03-18 Thread Elazar
בתאריך יום ג׳, 19 במרץ 2019, 0:41, מאת Greg Ewing ‏< greg.ew...@canterbury.ac.nz>: > Rémi Lapeyre wrote: > > > You can make "inferences from the way things are used". But the > > comparison with maths stops here, you don’t make such inferences because > your > > object must be well defined before

Re: [Python-ideas] Why operators are useful

2019-03-18 Thread Greg Ewing
Rémi Lapeyre wrote: You can make "inferences from the way things are used". But the comparison with maths stops here, you don’t make such inferences because your object must be well defined before you start using it. In maths texts it's very common to see things like 'Let y = f(x)...' where

Re: [Python-ideas] Why operators are useful

2019-03-18 Thread Jimmy Girardet
Hi, Please let me share my story of non experienced python programmer. Last year I wanted to merge three dicts  for config stuff. I found very quickly the answer : a = {**b, **c, **d} Sadly I was working on python 3.3 and that was nos possible to use this syntax. I don't remember what I did

Re: [Python-ideas] Why operators are useful

2019-03-18 Thread Antoine Pitrou
On Mon, 18 Mar 2019 14:06:53 + Rhodri James wrote: > On 16/03/2019 12:01, Gustavo Carneiro wrote: > > Already been said, but might have been forgotten, but the new proposed > > syntax: > > > > new = a + b > > > > has to compete with the already existing syntax: > > > > new =

Re: [Python-ideas] Why operators are useful

2019-03-18 Thread Rhodri James
On 16/03/2019 12:01, Gustavo Carneiro wrote: Already been said, but might have been forgotten, but the new proposed syntax: new = a + b has to compete with the already existing syntax: new = {**a, **b} That's easy. Whether it's spelt with "+" or "|" or pretty much anything

Re: [Python-ideas] Why operators are useful

2019-03-18 Thread Rémi Lapeyre
Le 17 mars 2019 à 02:01:51, Greg Ewing (greg.ew...@canterbury.ac.nz(mailto:greg.ew...@canterbury.ac.nz)) a écrit: > Richard Damon wrote: > > Rémi, I believe, is assuming in their example that by defining the field > > of mathematics being used, there is at least an implicit definition (if > > not

Re: [Python-ideas] Why operators are useful

2019-03-16 Thread Greg Ewing
Richard Damon wrote: Rémi, I believe, is assuming in their example that by defining the field of mathematics being used, there is at least an implicit definition (if not actually explicit as such a statement would typically be preceded by definitions) definition of the types of the variables.

Re: [Python-ideas] Why operators are useful

2019-03-16 Thread Terry Reedy
On 3/16/2019 8:01 AM, Gustavo Carneiro wrote: On Sat, 16 Mar 2019 at 10:33, Steven D'Aprano > wrote: The question this PEP is trying to answer is not "can we support every use-case imaginable for a merge operator?" but "can we support the most typical

Re: [Python-ideas] Why operators are useful

2019-03-16 Thread Gregory P. Smith
On Sat, Mar 16, 2019 at 5:02 AM Gustavo Carneiro wrote: > On Sat, 16 Mar 2019 at 10:33, Steven D'Aprano wrote: > >> On Fri, Mar 15, 2019 at 10:53:31PM +, MRAB wrote: >> >> > There was also the suggestion of having both << and >>. >> > >> > Actually, now that dicts are ordered, that would

Re: [Python-ideas] Why operators are useful

2019-03-16 Thread Richard Damon
On 3/16/19 8:14 AM, Dan Sommers wrote: > On 3/16/19 6:17 AM, Richard Damon wrote: >> On 3/16/19 4:39 AM, Greg Ewing wrote: >>> Rémi Lapeyre wrote: I think this omit a very important property of mathematic equations thought, maths is a very strongly typed language which can be a

Re: [Python-ideas] Why operators are useful

2019-03-16 Thread Kirill Balunov
сб, 16 мар. 2019 г. в 16:02, Kirill Balunov : > Thank you for this very thoughtful message! It reminded me of my first > experience with the old Fortran code. You probably know that earlier in > Fortran there were no cryptic shortcuts for writing relational operators: > instead of `A >= B`, you

Re: [Python-ideas] Why operators are useful

2019-03-16 Thread Kirill Balunov
Thank you for this very thoughtful message! It reminded me of my first experience with the old Fortran code. You probably know that earlier in Fortran there were no cryptic shortcuts for writing relational operators: instead of `A >= B`, you had to write `A .GE. B`, or as many often wrote this

Re: [Python-ideas] Why operators are useful

2019-03-16 Thread Rémi Lapeyre
Le 16 mars 2019 à 10:02:31, Greg Ewing (greg.ew...@canterbury.ac.nz(mailto:greg.ew...@canterbury.ac.nz)) a écrit: > Rémi Lapeyre wrote: > > I think this omit a very important property of > > mathematic equations thought, maths is a very strongly typed language > > which can be a significant

Re: [Python-ideas] Why operators are useful

2019-03-16 Thread Rémi Lapeyre
Le 16 mars 2019 à 13:15:37, Dan Sommers (2qdxy4rzwzuui...@potatochowder.com(mailto:2qdxy4rzwzuui...@potatochowder.com)) a écrit: > On 3/16/19 6:17 AM, Richard Damon wrote: > > On 3/16/19 4:39 AM, Greg Ewing wrote: > >> Rémi Lapeyre wrote: > >>> I think this omit a very important property of > >>>

Re: [Python-ideas] Why operators are useful

2019-03-16 Thread Rémi Lapeyre
Le 16 mars 2019 à 13:15:37, Dan Sommers (2qdxy4rzwzuui...@potatochowder.com(mailto:2qdxy4rzwzuui...@potatochowder.com)) a écrit: > On 3/16/19 6:17 AM, Richard Damon wrote: > > On 3/16/19 4:39 AM, Greg Ewing wrote: > >> Rémi Lapeyre wrote: > >>> I think this omit a very important property of > >>>

Re: [Python-ideas] Why operators are useful

2019-03-16 Thread Dan Sommers
On 3/16/19 6:17 AM, Richard Damon wrote: On 3/16/19 4:39 AM, Greg Ewing wrote: Rémi Lapeyre wrote: I think this omit a very important property of mathematic equations thought, maths is a very strongly typed language which can be a significant improvement for readability. Python is very

Re: [Python-ideas] Why operators are useful

2019-03-16 Thread Gustavo Carneiro
On Sat, 16 Mar 2019 at 10:33, Steven D'Aprano wrote: > On Fri, Mar 15, 2019 at 10:53:31PM +, MRAB wrote: > > > There was also the suggestion of having both << and >>. > > > > Actually, now that dicts are ordered, that would provide a use-case, > > because you would then be able to choose

Re: [Python-ideas] Why operators are useful

2019-03-16 Thread Richard Damon
On 3/16/19 4:39 AM, Greg Ewing wrote: > Rémi Lapeyre wrote: >> I think this omit a very important property of >> mathematic equations thought, maths is a very strongly typed language >> which can be a significant improvement for readability. > > Python is very strongly typed too, so I don't really

Re: [Python-ideas] Why operators are useful

2019-03-16 Thread Steven D'Aprano
On Sat, Mar 16, 2019 at 06:43:52AM +0400, Abdur-Rahmaan Janhangeer wrote: > Despite my poor python skills, i don't think i'd ever use this one. > > blocks = blocks + [block] # Not good for you. Neither would I. But I would use: result = process(blocks + [block]) in

Re: [Python-ideas] Why operators are useful

2019-03-16 Thread Antoine Pitrou
On Fri, 15 Mar 2019 10:51:11 -0700 Guido van Rossum wrote: > Of course, everything comes at a price. You have to learn the operators, > and you have to learn their properties when applied to different object > types. That's not the only price, though. If "+" is added to dicts, then we're

Re: [Python-ideas] Why operators are useful

2019-03-16 Thread Steven D'Aprano
On Fri, Mar 15, 2019 at 10:53:31PM +, MRAB wrote: > There was also the suggestion of having both << and >>. > > Actually, now that dicts are ordered, that would provide a use-case, > because you would then be able to choose which values were overwritten > whilst maintaining the order of

Re: [Python-ideas] Why operators are useful

2019-03-16 Thread Greg Ewing
Rémi Lapeyre wrote: I think this omit a very important property of mathematic equations thought, maths is a very strongly typed language which can be a significant improvement for readability. Python is very strongly typed too, so I don't really see how maths is different. For example, a

Re: [Python-ideas] Why operators are useful

2019-03-16 Thread Terry Reedy
I agree with Guido's general comments on operators. Modern arithmetic and algebra really took off with the introduction of operators. On the other hand, I have seen condensed blocks of 'higher math', dense with operators, that I could hardly read, and that reminded me of API or Perl. On

Re: [Python-ideas] Why operators are useful

2019-03-15 Thread Guido van Rossum
On Fri, Mar 15, 2019 at 9:19 PM Inada Naoki wrote: > On Sat, Mar 16, 2019 at 2:51 AM Guido van Rossum wrote: > > > > But I think that the folks who point out "there is already a way to do > this" are missing the point that it really is easier to grasp the meaning > of this: > > > > d = d1 +

Re: [Python-ideas] Why operators are useful

2019-03-15 Thread Inada Naoki
On Sat, Mar 16, 2019 at 2:51 AM Guido van Rossum wrote: > > But I think that the folks who point out "there is already a way to do this" > are missing the point that it really is easier to grasp the meaning of this: > > d = d1 + d2 > > compared to this: > > d = d1.copy() > d =

Re: [Python-ideas] Why operators are useful

2019-03-15 Thread Abdur-Rahmaan Janhangeer
Despite my poor python skills, i don't think i'd ever use this one. blocks = blocks + [block] # Not good for you. > ___ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of

Re: [Python-ideas] Why operators are useful

2019-03-15 Thread Chris Angelico
On Sat, Mar 16, 2019 at 1:27 PM Raymond Hettinger wrote: > > > On Mar 15, 2019, at 6:49 PM, Chris Angelico wrote: > > > > On Sat, Mar 16, 2019 at 12:40 PM Raymond Hettinger > > wrote: > >> Also, it seems like the efficiency concerns were dismissed with > >> hand-waving. But usually, coping and

Re: [Python-ideas] Why operators are useful

2019-03-15 Thread Raymond Hettinger
> On Mar 15, 2019, at 6:49 PM, Chris Angelico wrote: > > On Sat, Mar 16, 2019 at 12:40 PM Raymond Hettinger > wrote: >> Also, it seems like the efficiency concerns were dismissed with hand-waving. >> But usually, coping and updating aren't the desired behavior. When teaching >> Python, I

Re: [Python-ideas] Why operators are useful

2019-03-15 Thread Chris Angelico
On Sat, Mar 16, 2019 at 12:40 PM Raymond Hettinger wrote: > Also, it seems like the efficiency concerns were dismissed with hand-waving. > But usually, coping and updating aren't the desired behavior. When teaching > Python, I like to talk about how the design of the language nudges you >

Re: [Python-ideas] Why operators are useful

2019-03-15 Thread Raymond Hettinger
> On Mar 15, 2019, at 12:28 PM, Rhodri James wrote: > > I suspect this is a bit personal; I had sufficiently evil lecturers in my > university Algebra course that I still don't automatically take the > commutativity of "+" over a particular group as a given :-) Nothing is > obvious unless

Re: [Python-ideas] Why operators are useful

2019-03-15 Thread MRAB
On 2019-03-15 19:05, Jonathan Fine wrote:> Guido wrote: > >> There's been a lot of discussion about an operator to merge two dicts. I participated in the beginning but quickly felt overwhelmed by the endless repetition, so I muted most of the threads. > >> But I have been thinking about the

Re: [Python-ideas] Why operators are useful

2019-03-15 Thread Rhodri James
On 15/03/2019 18:54, Raymond Hettinger wrote: So, we have to ask whether we're stretching too far from "operators are good" to "we need this operator". Here are some considerations: Frequency of usage: Math provides ∑ and ∏ because they are common. It doesn't provide a special operator for

Re: [Python-ideas] Why operators are useful

2019-03-15 Thread Jonathan Fine
Raymond Hettinger wrote: > Frequency of usage: Math provides ∑ and ∏ because they are common. It > doesn't provide a special operator for sqrt(c**2 - b**2) because the latter > is less fundamental and less common. Here's some more information. Below is an example of an area, where sqrt(c**2

Re: [Python-ideas] Why operators are useful

2019-03-15 Thread Rémi Lapeyre
 Le 15 mars 2019 à 18:52:51, Guido van Rossum (gu...@python.org(mailto:gu...@python.org)) a écrit: … > The power of visual processing really becomes apparent when you combine > multiple operators. For example, consider the distributive law: > > mul(n, add(x, y)) == add(mul(n, x), mul(n, y)) (5)

Re: [Python-ideas] Why operators are useful

2019-03-15 Thread Jonathan Fine
Guido wrote: > There's been a lot of discussion about an operator to merge two dicts. I > participated in the beginning but quickly felt overwhelmed by the endless > repetition, so I muted most of the threads. > But I have been thinking about the reason (some) people like operators, and a >

Re: [Python-ideas] Why operators are useful

2019-03-15 Thread Raymond Hettinger
> On Mar 15, 2019, at 10:51 AM, Guido van Rossum wrote: > > The general idea here is that once you've learned this simple notation, > equations written using them are easier to *manipulate* than equations > written using functional notation -- it is as if our brains grasp the > operators

[Python-ideas] Why operators are useful

2019-03-15 Thread Guido van Rossum
There's been a lot of discussion about an operator to merge two dicts. I participated in the beginning but quickly felt overwhelmed by the endless repetition, so I muted most of the threads. But I have been thinking about the reason (some) people like operators, and a discussion I had with my