Perl6: Explain that Integers Can't be Passed and Modified in Sub's Even If Using `is rw´ (#2471)

* Explain that you cannot pass immutable values like integers to subs even if you use $n is rw.

* Add myself as a contributor

* Remove contributor since I am not a major contributor
This commit is contained in:
samcv 2016-10-18 09:59:13 -07:00 committed by ven
parent c08ca5b9c9
commit 0d11887c22

View File

@ -193,6 +193,15 @@ sub mutate($n is rw) {
say "\$n is now $n !"; say "\$n is now $n !";
} }
my $m = 42;
mutate $m; # $n is now 43 !
# This works because we are passing the container $m to mutate. If we try
# to just pass a number instead of passing a variable it won't work because
# there is no container being passed and integers are immutable by themselves:
mutate 42; # Parameter '$n' expected a writable container, but got Int value
# If what you want a copy instead, use `is copy`. # If what you want a copy instead, use `is copy`.
# A sub itself returns a container, which means it can be marked as rw: # A sub itself returns a container, which means it can be marked as rw: