copy (1)
a: [1 2 3]
b: a
b ;== [1 2 3]
append a 4
a ;== [1 2 3 4]
b ;== [1 2 3 4]
It works like that for more complex objects that are allocated on the heap with a pointer, such as the block in the example. For simple types that are allocated in the stack, such as numbers and dates, each variable gets its own value storage:
a: 20 ;== 20
b: a ;== 20
a: 25 ;== 25
b ;== 20
If you don’t want this behavior, you have to do b: copy a
, instead of b: a
as shown here:
a: [1 2 3]
b: copy a
b ;== [1 2 3]
append a 4
a ;== [1 2 3 4]
b ;== [1 2 3]