Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Deletes the second alternative for deep cloning
Which does not actually work. A small reflow here and there. Closes #2627
  • Loading branch information
JJ committed Feb 26, 2019
1 parent 22a1cb5 commit e0a4e7e
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions doc/Type/Mu.pod6
Expand Up @@ -245,18 +245,17 @@ with my $o2 = $o1.clone {
}
# Hash and Array attribute modifications in clone appear in original as well:
say $o1; # OUTPUT: «Foo.new(foo => 42, bar => ["Z", "Y"], baz => {:X("W"), :Z("Y")}, …␤»
say $o2; # OUTPUT: «Foo.new(foo => 70, bar => ["Z", "Y"], baz => {:X("W"), :Z("Y")}, …␤»
say $o1;
# OUTPUT: «Foo.new(foo => 42, bar => ["Z", "Y"], baz => {:X("W"), :Z("Y")}, …␤»
say $o2;
# OUTPUT: «Foo.new(foo => 70, bar => ["Z", "Y"], baz => {:X("W"), :Z("Y")}, …␤»
$o1.boo.(); # OUTPUT: «Hi␤»
$o2.boo.(); # OUTPUT: «Bye␤»
=end code
To clone those, you could implement your own C<.clone> that clones the
appropriate attributes and passes the new values to C<Mu.clone>, for example,
via L«C<nextwith>|/language/functions#sub_nextwith». Alternatively,
your own C<.clone> could clone self first
(using C<self.Mu::clone> or L«C<callsame>|/language/functions#sub_callsame»)
and then manipulate the clone as needed, before returning it.
via L«C<nextwith>|/language/functions#sub_nextwith».
=begin code
class Bar {
Expand All @@ -266,7 +265,7 @@ class Bar {
method clone { nextwith :foo(@!foo.clone), :bar(%!bar.clone), |%_ }
}
my $o1 = Bar.new;
my $o1 = Bar.new( :42quux );
with my $o2 = $o1.clone {
.foo = <Z Y>;
.bar = <Z Y X W>;
Expand Down

0 comments on commit e0a4e7e

Please sign in to comment.