Consider the code below.
function dummy()
A = zeros(2,2)
for i=1:2
for j=1:2
A(i,j) = rand() # should be A[i,j]
end
end
return A
end
It returns
julia> A=dummy()
A (generic function with 1 method)
which is very weird, since in the REPL writing A(i,j) instead of A[i,j] returns an error.
Is this a bug?
By contrast, if we use A[i,j] = rand() we get
julia> A=dummy()
2×2 Array{Float64,2}:
0.531469 0.218812
0.48418 0.581266
as expected.
Note that odd behavior also happens outside of functions, although it seems to have to be inside of a for loop. For example
A = zeros(2,2)
for i=1:2
for j=1:2
A(i,j) = rand() # should be A[i,j] = rand()
end
end
returns zeros(2,2).
Whereas if I write
A = zeros(2,2); A(1,1) = rand(); A(1,2) = rand(); A(2,1)=rand(); A(2,2)=rand()
I get a syntax error, as expected:
ERROR: syntax: "1" is not a valid function argument name
What is going on?