3 ms·
I for one feel that + is a very intuitive choice for concatenating strings and lists. Is there any other common operator you would recommend instead? Because I
by falcor84 8y ago
I for one feel that + is a very intuitive choice for concatenating strings and lists. Is there any other common operator you would recommend instead? Because I feel that using a less common one would harm beginner-friendliness significantly.
Also, to the best of my knowledge there is no place in the bible of maths that defines + to be commutative. In particular, addition of (infinite) ordinals is not commutative.
- enriquto 8y ago> I for one feel that + is a very intuitive choice for concatenating strings and lists. Is there any other common operator you would recommend instead? Literally, any other operator would be better than addition. A space, a dot, a product, two dots, a minus sign, whatever. Anything except the visually commutative plus. > Because I feel that using a less common one would harm beginner-friendliness significantly. Usage of + for string concatenation is fairly new, probably invented by C++ (which, by the way, uses bit shift operators for output, so it is not really an example of sane language).
- tomtimtall 8y ago“A”+”B” what do you feel should happen? “A”*6 what do you feel should happen?
- enriquto 8y ago> “A”+”B” what do you feel should happen? Clearly, that should be undefined. You cannot sum two strings. Unless you are really deranged and you want it to be "C".
- a1369209993 8y ago"A"+"B" = Regex("A|B") = Regex("[AB]") # or maybe "A"+"B" !> [?]Error: cannot convert /A|B/ to type str "A"*6 !> TypeError: <str> * <int>
- dragonwriter 8y ago> Because I feel that using a less common one would harm beginner-friendliness significantly. Actually, given that concatenating sequences (strings are an example) is a fairly common operation and for some kinds of sequences, so is adding them elementwise, it would be better not to use a common mathematical operator for concatenation, but to give it its own.
- a1369209993 8y ago> Is there any other common operator you would recommend instead? Yes, wedge product[0], written as tilde (~)[1]: "a"~("b"~"c") = "abc" = ("a"~"b")~"c" # associative "a"~"a"~"a" = "aaa" = "a"^3 # exponentiates with repeat -"abc" = "cba" # (with - as string reverse) "ab"~"cd" = -(-"cd" ~ -"ab") # weakly[2] anticommutative If you generalize to regular expressions, you can get some more milage out of + as alternation and * as intersection. 0: https://en.wikipedia.org/wiki/Wedge_product https://en.wikipedia.org/wiki/Wedge_product 1: Not caret (^), because that makes a good exponentiate operator. 2: # vector wedge product is strongly anticommutative u~v = -(v~u) = -(-v~-u) # with vector negation