When I was first starting I was horrified by this, when trying to literally translate Fortran to Julia:
julia> function f()
local x = Vector{Float64}(undef,3)
local y = Vector{Float64}(undef,3)
y[1] = 1.0
x = y
y[1] = 2.0
println(x[1])
end
f (generic function with 1 method)
julia> f()
2.0
Now I am used to it, and see that that is a price to pay to have a dynamically typed language. The fact that x
is not anymore the vector I defined at start was surprising and, of course, a source of errors that Fortran does not have. There are trade-offs.
edit: In fortran this returns “1.0”:
program main
implicit none
double precision :: x(3), y(3)
y(1) = 1.
x = y
y(1) = 2.
write(*,*) x(1)
end program main