The original CpxVector.
(setq x (new Vector: complex: 1 1.0 2.0))
|
Returns: #<CpxVector 123456>
|
The copied Vector using the copy function.
(setq z (copy x))
|
Returns: #<CpxVector 234567>
|
The copied Vector using the setq function.
(setq twin x)
|
Returns: #<CpxVector 345678>
|
After the first setq function, the values of CpxVector z are:
z[0]
|
Returns: #(cpx| #c1.0+2.0i )
|
After the first setq function, the value of Vector X is:
x[0]
|
Returns: #(cpx| #c1.0+2.0i )
|
The container named z is a copy of x (both are Vectors) 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[0] #c4.0+8.0i)
|
Returns: #<CpxVector 123456>
|
The setq command results in the contents of both twin and x being both the same.
twin[0]
|
Returns: #(cpx| #c4.0+8.0i )
|
x[0]
|
Returns: #(cpx| #c4.0+8.0i )
|
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.
z[0]
|
Returns: #(cpx| #c1.0+2.0i )
|
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.