Polymorphic copy: Difference between revisions
Content added Content deleted
(added MiniScript example) |
Thundergnat (talk | contribs) (Rename Perl 6 -> Raku, alphabetize, minor clean-up) |
||
Line 584: | Line 584: | ||
<pre>I'm the instance of S p: Y23 |
<pre>I'm the instance of S p: Y23 |
||
I'm the instance of S p: X23</pre> |
I'm the instance of S p: X23</pre> |
||
=={{header|Delphi}}== |
=={{header|Delphi}}== |
||
Line 681: | Line 680: | ||
😡 error: T : type-check failure : string-inside → 'K:box' |
😡 error: T : type-check failure : string-inside → 'K:box' |
||
</lang> |
</lang> |
||
=={{header|Elena}}== |
=={{header|Elena}}== |
||
ELENA 4.x : |
ELENA 4.x : |
||
Line 730: | Line 730: | ||
let s2 = s.Clone() // the static type of s2 is T, but it "points" to an S |
let s2 = s.Clone() // the static type of s2 is T, but it "points" to an S |
||
s2.Print() // prints "I'm an S!"</lang> |
s2.Print() // prints "I'm an S!"</lang> |
||
=={{header|Factor}}== |
=={{header|Factor}}== |
||
shallow copy is achieved with the "clone" word. |
shallow copy is achieved with the "clone" word. |
||
Line 746: | Line 747: | ||
C |
C |
||
C |
C |
||
=={{header|Forth}}== |
=={{header|Forth}}== |
||
{{works with|4tH|3.62.1}} |
{{works with|4tH|3.62.1}} |
||
Line 818: | Line 820: | ||
obj-t print-container \ class is S |
obj-t print-container \ class is S |
||
</lang> |
</lang> |
||
=={{header|Fortran}}== |
=={{header|Fortran}}== |
||
Tested with GNU gfortran 5.2.1 and INTEL ifort 16. |
Tested with GNU gfortran 5.2.1 and INTEL ifort 16. |
||
Line 1,110: | Line 1,113: | ||
Note that objects cannot be dereferenced. If you need polymorphic copy in J, you probably should not be using objects for that purpose. |
Note that objects cannot be dereferenced. If you need polymorphic copy in J, you probably should not be using objects for that purpose. |
||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
=={{header|Java}}== |
=={{header|Java}}== |
||
Line 1,151: | Line 1,142: | ||
System.out.println(copier(obj2).name()); // prints "S" |
System.out.println(copier(obj2).name()); // prints "S" |
||
} |
} |
||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
}</lang> |
}</lang> |
||
Line 1,208: | Line 1,211: | ||
j is the same as b? false |
j is the same as b? false |
||
</pre> |
</pre> |
||
=={{header|Kotlin}}== |
=={{header|Kotlin}}== |
||
Line 1,593: | Line 1,595: | ||
print "\$x is: "; |
print "\$x is: "; |
||
$x->manifest;</lang> |
$x->manifest;</lang> |
||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
=={{header|Phix}}== |
=={{header|Phix}}== |
||
Line 1,876: | Line 1,872: | ||
(#<class:point/color%> 0 0 black) |
(#<class:point/color%> 0 0 black) |
||
#f</pre> |
#f</pre> |
||
⚫ | |||
(formerly Perl 6) |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
=={{header|REXX}}== |
=={{header|REXX}}== |
||
Line 1,931: | Line 1,935: | ||
}</lang> |
}</lang> |
||
=={{header|Sidef}}== |
=={{header|Sidef}}== |
||
''Object.dclone()'' makes a deep clone of any mutable object and returns it to the caller. |
''Object.dclone()'' makes a deep clone of any mutable object and returns it to the caller. |