> 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?
Copylist copies a list. It does not copy its contents. To copy its
contents, you can write a simple recursive function:
copyall(l):=if listp(l) then map('copyall,l) else l;
Since 'map' makes a list of the results, it is creating a new list, so
you don't need copylist as well.
L:[a,[b],[[c]]]$
L1: copylist(L)$
L2: copyall(L)$
( L[1]:q, L[2][1]:r, L[3][1][1]: s );
L => [q, [r], [[s]]]
L1 => [a, [r], [[s]]]
L2 => [a, [b], [[c]]]
This does not copy lists nested within other structures, though:
xx: f([a])$
xx1: copyall(xx)$
part(xx,1)[1]: z$
xx => f([z])
xx1 => f([z])
If it's necessary, you can write your own recursive function to copy
these, too:
copyallall(l):=
block([inflag:true], /* operate on internal forms */
if atom(l) or subvarp(l) then l
else funmake(copyallall(part(l,0)),
map('copyallall,args(l))))$
If you really want to handle the obscure case f[[x]], then you'll need
this clause instead of "or subvarp(l)":
else if subvarp(l) then
arraymake(copyallall(part(l,0)),
map('copyallall,args(l)))
But you probably don't need anything as elaborate as copyallall, let
alone the subvarp case.
-s