Course of Raku / Advanced / Containers / Ordered containers / Exercises / Alias an array
Solution: Alias an array
Here is a possible solution to the task.
Code
my @original = 10, 20, 30;
my @alias := @original;
@original.push(40);
say @alias;🦋 You can find the source code in the file alias-an-array.raku.
Output
[10 20 30 40]Comments
The binding
@alias := @originalmakes@aliasanother name for the same array container, rather than a copy of it.The change is made through
@originalthis time, and it is a structural one —pushadds an element. Because both names are the very same container,@aliassees the new element too. The two names are completely interchangeable: it does not matter which one you use to read or to modify the array.