~ (tilde)
The concatenation operator.
Syntax
-
a ~ b[ ~ ⋯]
-
a
,b
, and⋯
are all strings, all vectors, or all lists
-
Description
-
If
a
,b
, ... are all strings, thena ~ b ~ ⋯
is the concatenation of all these strings. -
If
a
,b
, ... are all vectors, thena ~ b ~ ⋯
is the concatenation of all these vectors. -
If
a
,b
, ... are all lists, thena ~ b ~ ⋯
is the concatenation of all these lists.
Notes
The n-ary concatenation operator ~
is implemented by the concat
function.
For strings, the end result of a ~ b ~ ⋯
is the same as that of a + b + ⋯
, but the concatenation operator is more performant, partly because it is n-ary while +
is binary.
To join all strings in a list, use the join
function.
To create a string with variable parts from a template, use the format
function.
Examples
"alpha" ~ "beta" ~ "gamma"
alphabetagamma
❨5, 1, 2❩ ~ ❨−5, i, 2❩ ~ ❨1, 2, 3, 4❩ ~ ❨0❩
(5, 1, 2, −5, i, 2, 1, 2, 3, 4, 0)
'("alpha", 394, 713, π) ~ '(true, false, 5) ~ '(i, −i, color("red"))
alpha 394 713 3.14159265359 true false 5 i −i rgba(1.000, 0.000, 0.000, 1.000)