Greetings with the approaching New Year to all!
I have a problem with creating a copy of a list, which does not change when
the original is changed. Is it possible and how to do this?
In the example below, when I change original in (C1)-(D5) it is OK.
The copy does not change.
But if elements of a list are lists, changing original element inside the internal list changes its copy as well, (C6)-(D10), below. If I change the whole internal list, things go fine again, (C11)-(D15).
(C1) L:[a,b,c]$ M:copylist(L);
(C2)
(D2) [a, b, c]
(C3) L[1]:x$ L; M;
(C4)
(D4) [x, b, c]
(C5)
(D5) [a, b, c]
(C6) LL:[[aa,bb,cc],[xx,yy,zz]]$ MM:copylist(LL);
(C7)
(D7) [[aa, bb, cc], [xx, yy, zz]]
(C8) LL[1][1]:xxx$ LL; MM; # is it correct to use LL[1][1] here?
(C9)
(D9) [[xxx, bb, cc], [xx, yy, zz]]
(C10)
(D10) [[xxx, bb, cc], [xx, yy, zz]]
(C11) LL:[[aa,bb,cc],[xx,yy,zz]]$ MM:copylist(LL);
(C12)
(D12) [[aa, bb, cc], [xx, yy, zz]]
(C13) LL[1]:[aaa,bbb,ccc]$ LL; MM;
(C14)
(D14) [[aaa, bbb, ccc], [xx, yy, zz]]
(C15)
(D15) [[aa, bb, cc], [xx, yy, zz]]