It seems like it would be handy to have ++
as a generic concatenation operator. There are a few languages that use ++
for this, e.g. Erlang, Haskell, and Elm. For arrays, ++
would be sugar for vcat
(hcat
is another story). Here’s an example of the current syntax pulled from a unit test in MLJBase.jl:
N = 2
v = vcat(fill(:a, N), fill(:b, 2N), fill(:c, 3N), fill(:d, 4N))
Of course, Julia already has syntax sugar for vcat
, but in this case the sugar is not very sweet:
v = [fill(:a, N); fill(:b, 2N); fill(:c, 3N); fill(:d, 4N)]
Compare this to the proposed ++
operator:
v = fill(:a, N) ++ fill(:b, 2N) ++ fill(:c, 3N) ++ fill(:d, 4N)
I find the ++
operator to be more readable.
And of course ++
could be used for string concatenation:
s = "hello " ++ "world"
I don’t think I’m alone in finding *
to be unintuitive for string concatenation. And it seems to me like concatenation is mostly a separate concept from arithmetic, so it would be better not to overload arithmetic operators to perform concatenation.