Yes, spaces denote a new column in an array definition, so a[2 +1] is size
2 while a[2 + 1] has the parser not care about the spaces because it tries
to complete the expression (like it does with newlines). My favorite case
is this piece of code I wrote a few months ago:
Du(x) = [cos(2*π.*x(:,1)).*cos(2*π.*x(:,2))./(4*π) -sin(2π.*x(:,1)).*sin(2
π.*x(:,2))./(4π)]
Notice that because of the spacing in the middle, the result is an Nx2
matrix where the cosine terms are one column and the sin terms are another.
I just wish that I can add an explicit separator because -sin is two
columns vs - sin which makes one. Can there be an optional separator
syntax, like a comma? [1,2,3,4;1,2,3,4]? (Maybe there is but I just don't
know it)
On Tuesday, May 24, 2016 at 8:56:33 PM UTC-7, Po Choi wrote:
>
> julia> a = zeros(3)
> 3-element Array{Float64,1}:
> 0.0
> 0.0
> 0.0
>
> julia> a[2+1]
> 0.0
>
> julia> a[2 + 1]
> 0.0
>
> julia> a[2+ 1]
> 0.0
>
> julia> a[2 +1]
> ERROR: MethodError: `typed_hcat` has no method matching
> typed_hcat(::Array{Float64,1}, ::Int64, ::Int64)
> Closest candidates are:
> typed_hcat(::Type{T}, ::Number...)
> typed_hcat(::Type{T}, ::Any...)
>
> julia> a[(2 +1)]
> 0.0
>
>
>
>