Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The shallowness of .clone needs a more precise explanation. #1458

Closed
smls opened this issue Aug 19, 2017 · 0 comments
Closed

The shallowness of .clone needs a more precise explanation. #1458

smls opened this issue Aug 19, 2017 · 0 comments
Labels
docs Documentation issue (primary issue type) update part of "docs" - indicates this is an update for an existing section; rewrite, clarification, etc.

Comments

@smls
Copy link
Contributor

smls commented Aug 19, 2017

objects#Object_Cloning says:

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.

@smls smls added the docs Documentation issue (primary issue type) label Aug 19, 2017
@coke coke added the update part of "docs" - indicates this is an update for an existing section; rewrite, clarification, etc. label Aug 26, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Documentation issue (primary issue type) update part of "docs" - indicates this is an update for an existing section; rewrite, clarification, etc.
Projects
None yet
Development

No branches or pull requests

2 participants