Previous Up Next

25.2.9  Assignment by copying

The copy command creates a copy of its argument, which is typically a list of some type. If B is a list and A:=B, then A and B point to the same list, and so changing one will change the other. But if A:=copy(B), then A and B will point to different lists with the same values, and so can be changed individually.

Example

B:=[[4,5],[2,6]]:; A:=B:; C:=copy(B):; A,B,C
     
⎡
⎢
⎣
45
26
⎤
⎥
⎦
,
⎡
⎢
⎣
45
26
⎤
⎥
⎦
,
⎡
⎢
⎣
45
26
⎤
⎥
⎦
          
B[1]=<[0,0]:; A,B,C
     
⎡
⎢
⎣
45
00
⎤
⎥
⎦
,
⎡
⎢
⎣
45
00
⎤
⎥
⎦
,
⎡
⎢
⎣
45
26
⎤
⎥
⎦
          

Previous Up Next