Polymorphic copy: Difference between revisions

added MiniScript example
(added MiniScript example)
Line 1,239:
Dog 'a' is not the same object as Dog 'b'
</pre>
 
=={{header|MiniScript}}==
<lang MiniScript>T = {}
T.foo = function()
return "This is an instance of T"
end function
 
S = new T
S.foo = function()
return "This is an S for sure"
end function
 
instance = new S
print "instance.foo: " + instance.foo
 
copy = {}
copy = copy + instance // copies all elements
print "copy.foo: " + copy.foo
 
// And to prove this is a copy, and not a reference:
instance.bar = 1
copy.bar = 2
print "instance.bar: " + instance.bar
print "copy.bar: " + copy.bar</lang>
{{out}}
<pre>instance.foo: This is an S for sure
copy.foo: This is an S for sure
instance.bar: 1
copy.bar: 2</pre>
 
=={{header|NetRexx}}==
222

edits