Why is `where` syntax in Julia sensitive to new-line?

Viewed 762

In a different question on Stack Overflow the answer included the following function:

julia> function nzcols(b::SubArray{T,2,P,Tuple{UnitRange{Int64},UnitRange{Int64}}}) where {T,P<:SparseMatrixCSC}
           return collect(i+1-start(b.indexes[2]) 
             for i in b.indexes[2]
             if b.parent.colptr[i]<b.parent.colptr[i+1] && 
               inrange(b.parent.rowval[nzrange(b.parent,i)],b.indexes[1]))
       end
nzcols (generic function with 3 methods)

And it was parsed without error. When adding a new-line before where clause for readability, an error suddenly appeared:

julia> function nzcols(b::SubArray{T,2,P,Tuple{UnitRange{Int64},UnitRange{Int64}}})
        where {T,P<:SparseMatrixCSC}
           return collect(i+1-start(b.indexes[2]) 
             for i in b.indexes[2]
             if b.parent.colptr[i]<b.parent.colptr[i+1] && 
               inrange(b.parent.rowval[nzrange(b.parent,i)],b.indexes[1]))
       end
ERROR: syntax: space before "{" not allowed in "where {"

Finally, when the parameter list parenthesis is moved to the where line, the error disappears again:

julia> function nzcols(b::SubArray{T,2,P,Tuple{UnitRange{Int64},UnitRange{Int64}}}
        ) where {T,P<:SparseMatrixCSC}
           return collect(i+1-start(b.indexes[2]) 
             for i in b.indexes[2]
             if b.parent.colptr[i]<b.parent.colptr[i+1] && 
               inrange(b.parent.rowval[nzrange(b.parent,i)],b.indexes[1]))
       end
nzcols (generic function with 3 methods)

What is the logic behind this syntax and should it be fixed?

1 Answers
Related