Course of Raku / Advanced / Containers / Ordered containers / Exercises / Bind a scalar
Solution: Bind a scalar
Here is a possible solution to the task.
Code
my $source = 1;
my $bound := $source;
my $copy = $source;
$source = 9;
say $bound;
say $copy;🦋 You can find the source code in the file bind-a-scalar.raku.
Output
9
1Comments
Binding with
:=makes$boundanother name for the same container as$source, rather than a copy. So changing$sourceis visible through$bound, which prints9.Ordinary assignment with
=copies the value into a separate container, so$copyis unaffected by the later change and still prints1.Seeing the two side by side is the whole point:
:=shares a container,=duplicates the value.
Course navigation
← Bind a scalar | Contexts 🆕 →