Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
36
Task/Polymorphic-copy/Icon/polymorphic-copy.icon
Normal file
36
Task/Polymorphic-copy/Icon/polymorphic-copy.icon
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
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
|
||||
Loading…
Add table
Add a link
Reference in a new issue