3 ms·
I didn't realize that concatenating two strings was the same exact concept as adding two numbers together. You learn something new everyday. Oh, they're not?
by b2gills 6y ago
I didn't realize that concatenating two strings was the same exact concept as adding two numbers together.
You learn something new everyday.
Oh, they're not?
Then why are you using the same operator?
...
They reused the operator because you can say in English that “you are adding two strings together”, and have it be a perfectly reasonable sentence to say. As the designers were English speaking, it made enough sense to them to add it to that operator. If they spoke a different language, who knows what operator they would have used instead.
A better idea would be to allow people to add new operators. Even better if you can use that same feature to extend existing operators where it makes sense.
The reason few languages allow that is that their parsing system is still largely designed around the memory and speed tradeoffs that were required in the 1970s. As such it is difficult to alter the parser while it is parsing.
Raku has this feature, and it works by subclassing the current parser to add new operators. (It's intended that you can also temporarily replace it for one that parses an entirely different language.)