This article is from the FAQ, by with numerous contributions by others.
It is often useful to be able to make a genuine copy of an object. It is
currently being discussed to introduce a 'clone' operation into the object
pattern, which should take care of this copying automatically, but no
decision has been made as to how and when.
Until then, the following trick does the job:
P: (# (* internal P structures *)
copy:< (* generic copy operation *)
(# copyType: ##P;
theCopy: ^P;
do this(P)##->copyType##;
©Type[]->theCopy[];
(* insert here code to implement the copying
* of internal P structures into theCopy *)
INNER copy;
(* possible finalization of the copying process *)
exit theCopy[]
#)
#);
Q: P(# (* internal Q structures *)
copy::<
(# Qcopy: ^Q
do theCopy[]->Qcopy[];
(* insert here code to implement the copying
* of internal Q structures into Qcopy *)
INNER copy;
(* possible finalization of the Q copying process *)
#)
#);
R: Q(# (* internal R structures *)
copy::<
(# Rcopy: ^R
do theCopy[]->Rcopy[];
(* insert here code to implement the copying
* of internal R structures into Rcopy *)
INNER copy;
(* possible finalization of the R copying process *)
#)
#);
a: @R; aCopy: ^R;
a.copy->aCopy[]
Rcopy: ^R
do theCopy[]->Rcopy[]
 
Continue to: