The original Matrix.
(define x #(mat| "The " "Rain " "in " "Spain") )
|
Returns: #<Matrix 123456>
|
The copied Matrix using the copy function.
(setq z (copy x))
|
Returns: #<Matrix 234567>
|
The copied Matrix using the setq function.
(setq twin x)
|
Returns: #<Matrix 345678>
|
After the first setq function, the values of Matrix z are:
After the first setq function, the values of Matrix x are:
The container named z is a copy of x (both are Matrices) and z has a separate
memory space. However, the containers named x and twin point to the same memory
spaces on the heap. Therefore
(setq twin[1] "Hail" )
|
Returns: #<Matrix 123456>
|
The setq command results in the contents of both twin and x being both the same.
Since z points to a different memory space, it still retained the original value
which was copied from x before the values of x were modified.
Notes and Hints
Using the setq function results in objects having the same object id.
But the object that is being assigned the copied object has a
different object id than original object. In this example twin and
x have the same object id while z has a different object id.