Structure Usage

fill will re-use the same element multiple times, not make independent copies. Thus:

julia> tri = fill([1], 3) # the same array, 3 times
3-element Array{Array{Int64,1},1}:
 [1]
 [1]
 [1]

julia> push!(tri[1], 2) # mutate the sole inner array
2-element Array{Int64,1}:
 1
 2

julia> tri
3-element Array{Array{Int64,1},1}:
 [1, 2]
 [1, 2]
 [1, 2]

julia> tri[3] = [3,4,5]; # replace an element of the outer array

julia> tri
3-element Array{Array{Int64,1},1}:
 [1, 2]
 [1, 2]
 [3, 4, 5]
2 Likes