Abusing operators

was surprised to find this is a valid Julia code:

julia> ==(==,==)

This fails, though:

julia> == == ==
ERROR: syntax: "==" is not a unary operator

I think both should parse the same, not that anyone sane would write either expression (hmm…)

You just need parentheses:

julia> (==) == (==)

This isn’t really abuse — nearly all “operators” are functions themselves and can be called as such. They just have special parsing that can make it tricky for Julia to see the function call as a function call or the infix operator syntax as infix syntax, so parentheses are sometimes required to disambiguate.


Or even

julia> (==) == ==

just to prevent the first == from being tried as a unary operator.