I want to reshape a matrix inside of a function, so I "declared" an array outside of the function and used reshape()
in the function. It doesn't really work, even though array is mutable.
julia> my_array = 1:10
1:10
julia> function test(array)
array = reshape(array, 2, 5)
println(array)
end
test (generic function with 1 method)
julia> test(my_array)
[1 3 5 7 9; 2 4 6 8 10]
julia> println(my_array)
1:10
Inside of the function, my_array
has been reshaped into a 2*5 matrix, but it restores the 1:10 after executing the function.
I am wondering the reason behind that, and how can I reshape a global array inside of function?
EDIT: My problem is different from variable references in lisp, I know the idea of passing a copy of variable into stack. For this problem, I don't know why the specific function reshape()
does not change array's contents, even if I pass the reference of a mutable object.