Polymorphic copy: Difference between revisions
Content added Content deleted
(Added Slate implementation) |
|||
Line 453: | Line 453: | ||
puts obj1.dup.name # prints "T" |
puts obj1.dup.name # prints "T" |
||
puts obj2.dup.name # prints "S"</lang> |
puts obj2.dup.name # prints "S"</lang> |
||
=={{header|Slate}}== |
|||
All objects in Slate may be <tt>clone</tt>d unless they are clones of <tt>Oddball</tt> (like <tt>True</tt>, <tt>False</tt>, and <tt>Nil</tt>) or are word-size Integers (which are encoded as tagged pointer values). This is a shallow copy where no values held in the object's slots are replaced with copies. There is also a <tt>copy</tt> method which is universal and overridden to perform deep copies as appropriate - copying continues via recursion through slot values and should be modified on any type where equality (<tt>=</tt>) is overridden. |
|||
<lang slate> |
|||
define: #T &parents: {Cloneable}. |
|||
define: #S &parents: {Cloneable}. |
|||
define: #obj1 -> T clone. |
|||
define: #obj2 -> S clone. |
|||
obj1 printName. |
|||
obj2 printName. |
|||
</lang> |
|||
=={{header|Tcl}}== |
=={{header|Tcl}}== |