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);

g := proc (x) x+y end proc; g(1) := 2

This includes a copy of f 's remember table:

> g(1);

2

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) := 3

g(3) := 4

> f(2) <> g(2), f(3) <> g(3);

3 <> 2+y, 3+y <> 4

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;

M := module () local L; export Put, Get, F; end mod...

> N:= Copy(M);

N := module () local L; export Put, Get, F; end mod...

Check that the local variables of M and N are separate.

> N:-Put(n); M:-Put(m);

n

m

> N:-Get() <> M:-Get();

n <> m

The remember table of the exported procedure F has been copied.

> M:-F(1); N:-F(1);

2

2

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);

3 <> 2+y, 3+y <> 4

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 := TABLE([b = proc (x) options operator, arrow; x...

> T[a](2),T[b](3);

3, 4

> TC:= Copy(T);

TC := TABLE([b = proc (x) options operator, arrow; ...

> TC[a](2),TC[b](3);

3, 4

> TC[a](2):= 5;

TC[a](2) := 5

> TC[a](2)=T[a](2);

5 = 5

Recursive copy of a table: now the remember tables are different.

> TC:= Copy(T,recursive);

TC := TABLE([b = proc (x) options operator, arrow; ...

> T[a](2):= 6; TC[a](2):= 7;

T[a](2) := 6

TC[a](2) := 7

> T[a](2) <> TC[a](2);

6 <> 7

See also:

copy , module , procedure , rtable

Maple Advisor Database R. Israel, 2001