class T() method a(); write("This is T's a"); end end class S: T() method a(); write("This is S's a"); end end procedure main() write("S:",deepcopy(S()).a()) end procedure deepcopy(A, cache) #: return a deepcopy of A local k /cache := table() # used to handle multireferenced objects if \cache[A] then return cache[A] case type(A) of { "table"|"list": { cache[A] := copy(A) every cache[A][k := key(A)] := deepcopy(A[k], cache) } "set": { cache[A] := set() every insert(cache[A], deepcopy(!A, cache)) } default: { # records and objects (encoded as records) cache[A] := copy(A) if match("record ",image(A)) then { every cache[A][k := key(A)] := deepcopy(A[k], cache) } } } return .cache[A] end