4 ms·
Arguably the simplest notation for string concatenation would be just concatenation (which would be the notation for multiplication, hence why Julia's choice co
by contravariant 7y ago
Arguably the simplest notation for string concatenation would be just concatenation (which would be the notation for multiplication, hence why Julia's choice could be argued to eb the most natural). Unfortunately programming languages can't quite deal with the ambiguity of having `a (x + y)` and `f(x)` refer to different operations.
Some languages seem to allow it for string literals though.
- leethargo 7y agoIn Julia, you can actually omit the `*` for multiplication, if it involves literals, i.e. julia> x = 10 10 julia> 2x 20 julia> 2 x ERROR: syntax: extra token "x" after end of expression But you have to be careful not to use white space either.
- yunruse 7y agoThat’s quite clever, actually. This way you could chain a complex string together with parentheses without needing a lot of pluses. Not the most useful of features, but it does explain why * is the concat operator.
- Avshalom 7y agoWell now I want a language to overload white space as an operator
- gpderetta 7y agoC++2000 has you covered: http://www.stroustrup.com/whitespace98.pdf http://www.stroustrup.com/whitespace98.pdf