Function: Copy - true copy for modules, procedures, etc.
Calling sequence:
Copy(x)
Copy(x, 'recursive')
Parameters:
x - anything
Description:
Examples:
Copying a procedure (with its remember table).
>
f:= proc(x) x + y end:
f(1):= 2:
g:= Copy(f);
This includes a copy of f 's remember table:
> g(1);
However, the two remember tables are now separate, and changes to one are not reflected in the other.
> f(2):= 3; g(3):= 4;
> f(2) <> g(2), f(3) <> g(3);
Copying a module.
>
M:= module() local L; export Put, Get, F;
Put:= proc(x) L:= x end;
Get:= proc() L end;
F:= x -> x + y; F(1):= 2;
end;
> N:= Copy(M);
Check that the local variables of M and N are separate.
> N:-Put(n); M:-Put(m);
> N:-Get() <> M:-Get();
The remember table of the exported procedure F has been copied.
> M:-F(1); N:-F(1);
These remember tables are separate.
>
M:-F(2):= 3: N:-F(3):= 4:
M:-F(2) <> N:-F(2), M:-F(3) <> N:-F(3);
Copying a table. This version is not recursive, so the entries refer to the same procedure (with the same remember table).
> T:= table([a = eval(M:-F), b = eval(N:-F)]);
> T[a](2),T[b](3);
> TC:= Copy(T);
> TC[a](2),TC[b](3);
> TC[a](2):= 5;
> TC[a](2)=T[a](2);
Recursive copy of a table: now the remember tables are different.
> TC:= Copy(T,recursive);
> T[a](2):= 6; TC[a](2):= 7;
> T[a](2) <> TC[a](2);
See also:
copy , module , procedure , rtable
Maple Advisor Database R. Israel, 2001