On Wed, Oct 13, 2021 at 7:57 PM Marc-Andre Lemburg <mal@egenix.com> 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 suffixes from strings is a rather common operation.
+1, although it's debatable whether it should be remove suffix or remove all. I'd be happy with either.
Removing prefixes is common as well, so perhaps "~" could be mapped to str.removeprefix():
s = 'abcdef' ~ 'abc'
giving
s == 'def'
Less obvious but convenient also. Unfortunately, tilde is a unary operator, so this won't actually work.
In a similar way, "/" could be mapped to str.split(), since that's probably even more common:
l = 'a,b,c,d' / ','
giving:
l == ['a', 'b', 'c', 'd']
Definitely. In any language that supports this, I use it frequently. It should be matched with seq*str to join: ["a", "b", "c","d"] * "," to give "a,b,c,d".
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
In my experience, there's often one constant and one variable involved, such as: lines = data / "\n" words = line / " " outputfile = inputfile - ".md" + ".html"
By adding such operators we could potentially make math functions compatible with strings by the way of duck typing, giving some really weird results, instead of errors.
Maybe, but I wouldn't consider that to be a particularly high priority. If they work, great, if they don't, so be it. The math module itself is primarily focused on float math, not even int. +1. ChrisA