Weird parsing inside [...]


#1

The following is a really hard to spot parsing nuance:

julia> [0 -1]
1×2 Array{Int64,2}:
 0  -1

julia> [0-1]
1-element Array{Int64,1}:
 -1

julia> [0 - 1]
1-element Array{Int64,1}:
 -1

julia> 0 -1
-1


#2

This is no weird at all, it is how arrays work. If you used MATLAB before, you should know that spaces inside [] mean new columns, except for operators - + * / ..., they must be evaluated first, the same holds in Julia.

This means:

[0 -1] => hcat(0, -1)
[0-1] => [-1]
[0 - 1] => [-1]

#3

Still, there is a tendency in Julia to warn or deprecate ambiguous syntax, eg in v0.7 the following were fixed:

So discussion about this would not be without precedent. I vaguely recall an issue which had something to do with [0 - 1], but can’t find it ATM.


#4

These things can be really hard to spot if you don’t know what you are looking for, it reminds me of R’s x<-y.