Polymorphic copy: Difference between revisions

Rename Perl 6 -> Raku, alphabetize, minor clean-up
(added MiniScript example)
(Rename Perl 6 -> Raku, alphabetize, minor clean-up)
Line 584:
<pre>I'm the instance of S p: Y23
I'm the instance of S p: X23</pre>
 
 
=={{header|Delphi}}==
Line 681 ⟶ 680:
😡 error: T : type-check failure : string-inside → 'K:box'
</lang>
 
=={{header|Elena}}==
ELENA 4.x :
Line 730:
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>
 
=={{header|Factor}}==
shallow copy is achieved with the "clone" word.
Line 746 ⟶ 747:
C
C
 
=={{header|Forth}}==
{{works with|4tH|3.62.1}}
Line 818 ⟶ 820:
obj-t print-container \ class is S
</lang>
 
=={{header|Fortran}}==
Tested with GNU gfortran 5.2.1 and INTEL ifort 16.
Line 1,110 ⟶ 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.
 
=={{header|JavaScript}}==
Copied from [http://keithdevens.com/weblog/archive/2007/Jun/07/javascript.clone here]:
<lang javascript>function clone(obj){
if (obj == null || typeof(obj) != 'object')
return obj;
 
var temp = {};
for (var key in obj)
temp[key] = clone(obj[key]);
return temp;
}</lang>
 
=={{header|Java}}==
Line 1,151 ⟶ 1,142:
System.out.println(copier(obj2).name()); // prints "S"
}
}</lang>
 
=={{header|JavaScript}}==
Copied from [http://keithdevens.com/weblog/archive/2007/Jun/07/javascript.clone here]:
<lang javascript>function clone(obj){
if (obj == null || typeof(obj) != 'object')
return obj;
 
var temp = {};
for (var key in obj)
temp[key] = clone(obj[key]);
return temp;
}</lang>
 
Line 1,208 ⟶ 1,211:
j is the same as b? false
</pre>
 
 
=={{header|Kotlin}}==
Line 1,593 ⟶ 1,595:
print "\$x is: ";
$x->manifest;</lang>
=={{header|Perl 6}}==
<lang perl6>my Cool $x = 22/7 but role Fink { method brag { say "I'm a cool {self.WHAT.perl}!" }}
my Cool $y = $x.clone;
$y.brag;</lang>
{{out}}
<pre>I'm a cool Rat+Fink!</pre>
 
=={{header|Phix}}==
Line 1,876 ⟶ 1,872:
(#<class:point/color%> 0 0 black)
#f</pre>
 
=={{header|Perl 6Raku}}==
(formerly Perl 6)
<lang perl6>my Cool $x = 22/7 but role Fink { method brag { say "I'm a cool {self.WHAT.perl}!" }}
my Cool $y = $x.clone;
$y.brag;</lang>
{{out}}
<pre>I'm a cool Rat+Fink!</pre>
 
=={{header|REXX}}==
Line 1,931 ⟶ 1,935:
 
}</lang>
 
=={{header|Sidef}}==
''Object.dclone()'' makes a deep clone of any mutable object and returns it to the caller.
10,333

edits