-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Closed
Description
Consider:
function foo(x)
y = convert(Vector{Float64},x)
y[1] = 10.0
return y
end
julia> x = [1,2,3]
3-element Array{Int64,1}:
1
2
3
julia> foo(x)
3-element Array{Float64,1}:
10.0
2.0
3.0
julia> x
3-element Array{Int64,1}:
1
2
3
julia> x = [1.,2.,3.]
3-element Array{Float64,1}:
1.0
2.0
3.0
julia> foo(x)
3-element Array{Float64,1}:
10.0
2.0
3.0
julia> x
3-element Array{Float64,1}:
10.0
2.0
3.0
The input is modified in one case, and not the other, which is in the realms of "scary". One (The?) solution is to always do a copy, even if the type matches, for mutable types.
Metadata
Metadata
Assignees
Labels
No labels