The image is wrong, "11" - 1 returns 10, not "10"
Subtraction is only valid for numbers, so both sides are coerced to a number before subtraction
However, addition means concatenation if at least one side is a string
What's your favorite language Jow Forums?
no, in a high level language it should give an invalid argument exception or similar because its not a supported / defined functionality
then if you wanted to you could overload the operator and define what it should do for a given class
It means the same as when you search a word in a dictionary and has various meanings.
No, I disagree. A high level language is allowed to have built-in operator overloads.
but even youre example shows how dumb it is to just pick something like that
should it remove all instances of that? the first instance? the last? only remove it if its the end of the string? youve created something which isnt clear what it will do as well as only being useful in few limited circumstances
>string concatenation concatenates strings
>subtraction subtracts numbers
Wow.
And this is where regular expressions come into play. Particularly the g flag.
So yeah, subtracting just a string should remove all instances, although you're right that it's not entirely clear what it should do. But subtracting a regular expression would have better-defined behavior, particularly if the g flag is allowed. Additionally, you could have the subscript operator overloaded by default so that if you subscript a string with a regular expression, you get matches, and if you assign a value to a regular expression subscript of a string, it does a replace.
lua is great
This