File tree Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Original file line number Diff line number Diff line change @@ -94,6 +94,32 @@ Example:
94
94
say @a.elems; # OUTPUT: «6»
95
95
say @a; # OUTPUT: «[a b c d e f]»
96
96
97
+ = head2 method clone
98
+
99
+ Defined as:
100
+
101
+ method clone(Array:D: --> Array:D)
102
+
103
+ Clones the original C < Array > . Modifications of elements in the clone
104
+ are not propagated to the original and vice-versa:
105
+
106
+ my @a = <a b c>; my @b = @a.clone;
107
+ @b[1] = 42; @a.push: 72;
108
+ say @b; # OUTPUT: «[a 42 c]»
109
+ say @a; # OUTPUT: «[a b c 72]»
110
+
111
+ However, note that the reifier I < is > shared between the two Arrays,
112
+ so both Arrays will have the same elements even when each is randomly-generated
113
+ on reification and each element will be reified just once, regardless of
114
+ whether the reification was done by the clone or the original Array.
115
+ B < Note: > just as reifying an Array from multiple threads is not safe,
116
+ so is, for example, reifying the clone from one thread while reifying
117
+ the original from another thread is not safe.
118
+
119
+ my @a = 1, {rand} … ∞; my @b = @a.clone;
120
+ say @b[^3]; # OUTPUT: «(1 0.0216426755282736 0.567660896142156)»
121
+ say @a[^3]; # OUTPUT: «(1 0.0216426755282736 0.567660896142156)»
122
+
97
123
= head2 routine shift
98
124
99
125
Defined as:
You can’t perform that action at this time.
0 commit comments