[Python-ideas] Re: Implementing additional string operators

2021-10-14 Thread Stephen J. Turnbull
Peter Ludemann writes: > From a mathematical point of view, x+y is equivalent to y+x, Yes, other things being equal, mathematical purists would prefer '*' to '+' for string concatenation *because* it's not commutative, but they're not equal. I imagine a good majority of folks can guess what '"

[Python-ideas] Re: Implementing additional string operators

2021-10-13 Thread Serhiy Storchaka
13.10.21 22:03, Marc-Andre Lemburg пише: > Some examples: > - removal of file extensions > - removal of end tags > - removal of units > - removal of currencies > - removal of standard suffixes > - removal of wildcard patterns > etc. > > I find lots of such uses in the code bases I work with. I di

[Python-ideas] Re: Implementing additional string operators

2021-10-13 Thread Serhiy Storchaka
13.10.21 22:53, Peter Ludemann пише: > [*] Floating point x+y isn't always y+x, but floating point is its own > problematic world. AFAIK floating point x+y is always y+x, but (x+y)+z is not always x+(y+z). ___ Python-ideas mailing list -- python-ideas@

[Python-ideas] Re: Implementing additional string operators

2021-10-13 Thread Peter Ludemann
MRAB wrote: > From a mathematical point of view, x-y is equivalent to x+(-y). >From a mathematical point of view, x+y is equivalent to y+x, but I suppose >that ship has sailed a long long time ago. ("++", "--", etc. would have been >better choices for operators)[*] Anyway, if you're going to a

[Python-ideas] Re: Implementing additional string operators

2021-10-13 Thread Marc-Andre Lemburg
On 13.10.2021 20:47, Paul Moore wrote: > On Wed, 13 Oct 2021 at 19:02, <2qdxy4rzwzuui...@potatochowder.com> wrote: > >> So aside from filename extensions, what are the real use cases for >> suffix removal? Plurals? No, too locale-dependent and too many >> exceptions. Whitespace left over from e

[Python-ideas] Re: Implementing additional string operators

2021-10-13 Thread Paul Moore
On Wed, 13 Oct 2021 at 19:02, <2qdxy4rzwzuui...@potatochowder.com> wrote: > So aside from filename extensions, what are the real use cases for > suffix removal? Plurals? No, too locale-dependent and too many > exceptions. Whitespace left over from external data? No, there's > already other fun

[Python-ideas] Re: Implementing additional string operators

2021-10-13 Thread Abdur-Rahmaan Janhangeer
Greetings list, Looking at the examples, I'm not sure how well this would play out in the context of just using variables, though: s = a - s s = a / c s = a ~ p By adding such operators we could potentially make math functions compatible with strings by the way of duck typing, giving some really

[Python-ideas] Re: Implementing additional string operators

2021-10-13 Thread 2QdxY4RzWzUUiLuE
On 2021-10-14 at 04:34:24 +1100, Chris Angelico wrote: > On Thu, Oct 14, 2021 at 2:21 AM <2qdxy4rzwzuui...@potatochowder.com> wrote: > > > > On 2021-10-14 at 00:00:25 +0900, > > "Stephen J. Turnbull" wrote: > > > > > Chris Angelico writes: > > > > > > > +1, although it's debatable whether it sh

[Python-ideas] Re: Implementing additional string operators

2021-10-13 Thread Chris Angelico
On Thu, Oct 14, 2021 at 2:21 AM <2qdxy4rzwzuui...@potatochowder.com> wrote: > > On 2021-10-14 at 00:00:25 +0900, > "Stephen J. Turnbull" wrote: > > > Chris Angelico writes: > > > > > +1, although it's debatable whether it should be remove suffix or > > > remove all. I'd be happy with either. > >

[Python-ideas] Re: Implementing additional string operators

2021-10-13 Thread MRAB
On 2021-10-13 16:26, Marc-Andre Lemburg wrote: On 13.10.2021 17:11, Guido van Rossum wrote: Maybe we should only accept operators as aliases for existing methods. x-y could mean x.removesuffix(y) That was the idea, yes, in particular to make it similar to "+", which adds to the end of the str

[Python-ideas] Re: Implementing additional string operators

2021-10-13 Thread Marc-Andre Lemburg
On 13.10.2021 17:11, Guido van Rossum wrote: > Maybe we should only accept operators as aliases for existing methods. > > x-y could mean x.removesuffix(y) That was the idea, yes, in particular to make it similar to "+", which adds to the end of the string, so that: s = x - oldend + newend works

[Python-ideas] Re: Implementing additional string operators

2021-10-13 Thread 2QdxY4RzWzUUiLuE
On 2021-10-14 at 00:00:25 +0900, "Stephen J. Turnbull" wrote: > Chris Angelico writes: > > > +1, although it's debatable whether it should be remove suffix or > > remove all. I'd be happy with either. > > If by "remove all" you mean "efefef" - "ef" == "", I think that's a > footgun. Similarl

[Python-ideas] Re: Implementing additional string operators

2021-10-13 Thread Ricky Teachey
On Wed, Oct 13, 2021, 11:01 AM Stephen J. Turnbull < stephenjturnb...@gmail.com> wrote: Chris Angelico writes: > +1, although it's debatable whether it should be remove suffix or > remove all. I'd be happy with either. If by "remove all" you mean "efefef" - "ef" == "", I think that's a footgun

[Python-ideas] Re: Implementing additional string operators

2021-10-13 Thread Guido van Rossum
Maybe we should only accept operators as aliases for existing methods. x-y could mean x.removesuffix(y) I don't think x~y is intuitive enough to use. On Wed, Oct 13, 2021 at 8:03 AM Stephen J. Turnbull < stephenjturnb...@gmail.com> wrote: > Chris Angelico writes: > > > +1, although it's debata

[Python-ideas] Re: Implementing additional string operators

2021-10-13 Thread Stephen J. Turnbull
Chris Angelico writes: > +1, although it's debatable whether it should be remove suffix or > remove all. I'd be happy with either. If by "remove all" you mean "efefef" - "ef" == "", I think that's a footgun. Similarly for "efabcd" - "ef" == "abcdef" - "ef". Steve ___

[Python-ideas] Re: Implementing additional string operators

2021-10-13 Thread Chris Angelico
On Wed, Oct 13, 2021 at 7:57 PM Marc-Andre Lemburg wrote: > > The idea to use "-" in the context of strings may have some > merrit. Not as unary minus, but as sequence operation and > shorthand for str.removesuffix(x): > > s = 'abc' + 'def' - 'ef' + 'gh' > > giving > > s == 'abcdgh' > > Removing s