copy
create a duplicate table, rtable, or module
Calling Sequence
Parameters
Description
Examples
copy( a )
copy( a , deep)
a
-
any expression
The purpose of the copy function is to create a duplicate table, rtable, or record which can be altered without changing the original table, rtable, or record. If a is not a table, rtable, or record, and a deep copy is not requested, a is returned.
This functionality is necessary since the statements s := table(); t := s; leave both names s and t evaluating to the same table structure. Hence, unlike other Maple data structures, assignments made via one of the names affect the values associated with the other name as well.
Note that copy is not recursive. This means that if a is a table of tables, the table data structure for a is copied but the table structures for the entries of a are not copied. To obtain a full recursive copy where all contents that are also mutable structures are copied, or to obtain a copy of a module, use the deep option.
For an rtable, copy preserves rtable options and indexing functions, except for the readonly option, which is not set, and the source_rtable attribute.
s1≔x
t≔s
t1≔y
s1
y
u≔copy⁡s
u≔table⁡1=y
u1≔z
m≔Matrix⁡1,shape=symmetric,a,readonly
m≔a
MatrixOptions⁡m
shape=symmetric,datatype=anything,storage=triangularupper,order=Fortran_order,readonly
n≔copy⁡m
n≔a
MatrixOptions⁡n
shape=symmetric,datatype=anything,storage=triangularupper,order=Fortran_order
For a table 'a' that contains another table 'b'; when copy is done on 'a' an entirely new copy of 'a' is created. However the objects contained in the table are not duplicated; so both 'a' and the copy of 'a' contain the table 'b'. Thus, if a change is made to the table 'b' in 'a', that change will show up in the copy of 'a' as well, and vice versa.
S≔table⁡45,table⁡symmetric,1,2=3
S≔table⁡1=45,2=table⁡symmetric,1,2=3
S1
45
T≔copy⁡S
T≔table⁡1=45,2=table⁡symmetric,1,2=3
T1
T1≔50
S22,1
3
T22,1≔5
5
For a list of records, deep must be used to obtain unique instances of the records.
rl≔Record⁡a=1,b=2,Record⁡a=3,b=4
rl_copy≔copy⁡rl
rl_copy≔Record⁡a=1,b=2,Record⁡a=3,b=4
rl_deep≔copy⁡rl,deep
rl_deep≔Record⁡a=1,b=2,Record⁡a=3,b=4
rl1a≔7
rl_copy1a
7
rl_deep1a
1
See Also
Array
Matrix
rtable
table
Vector
Download Help Document