You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This cloning is shallow since it only binds attributes to the same values contained in the original object; it does not make copies of those values.
I don't think that's completely accurate.
A $. attribute does get a fresh Scalar container, and the value from the old object's attribute gets assigned into it:
class A { has $.x is rw }
my$a = A.new(x=> 2);
my$b = $a.clone;
$b.x = 10;
say$a; # A.new(x => 2)
say $b; # B.new(x => 10)
...whereas a @. attributes doesn't get a fresh Array container, but rather gets the Array from the old object's attribute bound to it.
So it's more like how arguments are passed to $ and @ parameters in a signature, than simple := binding.
Not sure how to properly word that for the docs.
The text was updated successfully, but these errors were encountered:
objects#Object_Cloning says:
I don't think that's completely accurate.
A
$.attribute does get a freshScalarcontainer, and the value from the old object's attribute gets assigned into it:class A { has $.x is rw } my $a = A.new(x => 2); my $b = $a.clone; $b.x = 10; say $a; # A.new(x => 2) say $b; # B.new(x => 10)...whereas a
@.attributes doesn't get a freshArraycontainer, but rather gets theArrayfrom the old object's attribute bound to it.So it's more like how arguments are passed to
$and@parameters in a signature, than simple:=binding.Not sure how to properly word that for the docs.
The text was updated successfully, but these errors were encountered: