Which operators are parsed as chains?

I asked this over at the metaprogramming Slack channel but got no replies, so another try:

I thought all repeated binary operators are parsed as a chain, but apprearently that is not the case:

julia> Meta.show_sexpr(:(a ⊗ b ⊗ c))
(:call, :⊗, (:call, :⊗, :a, :b), :c)
julia> Meta.show_sexpr(:(a + b + c))
(:call, :+, :a, :b, :c)

For which operators exactly does that work?

2 Likes

I am not sure it is explicitly documented, but the source suggests that the only operators that do this are +, ++, and *.

3 Likes

Oh, intersting, thanks.

What is ++ used for? I think I’ve never seen it, but appearently there’s something to it if it is parsed specially.

It was used for https://github.com/pkofod/PlusPlus.jl :slight_smile:

2 Likes

It was a potential generic sequence concatenation operator, but that never really took off. The reason for n-ary parsing is because otherwise concatenating many sequences (e.g. strings) would be inefficient, allocating a temporary for each operator.

1 Like