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
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
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]
Still, there is a tendency in Julia to warn or deprecate ambiguous syntax, eg in v0.7 the following were fixed:
https://github.com/JuliaLang/julia/issues/16356
https://github.com/JuliaLang/julia/issues/19089
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.
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
.