Julia: array assignment behaviour

Viewed 267

My question is about the change of array elements. Consider the following code snippet:

julia> a = [1 2; 3 4]
2×2 Array{Int64,2}:
 1  2
 3  4

julia> b = a
2×2 Array{Int64,2}:
 1  2
 3  4

julia> a[1,1] = -1
-1

julia> b
2×2 Array{Int64,2}:
 -1  2
  3  4

However, when I run the following instead:

julia> a = [1 2; 3 4]
2×2 Array{Int64,2}:
 1  2
 3  4

julia> b = a
2×2 Array{Int64,2}:
 1  2
 3  4

julia> a = [5 6; 7 8]
2×2 Array{Int64,2}:
 5  6
 7  8

julia> b
2×2 Array{Int64,2}:
 1  2
 3  4

Array b remains unchanged? Why is that, can anyone explain this?

1 Answers
Related