diff options
author | samcv <samantham@posteo.net> | 2016-10-18 09:59:13 -0700 |
---|---|---|
committer | ven <vendethiel@hotmail.fr> | 2016-10-18 18:59:13 +0200 |
commit | 0d11887c222ca23ec3f4a50e46fd36de6e568942 (patch) | |
tree | 5cbdc2b3b964d1875bad5533c2b1336b73720a37 | |
parent | c08ca5b9c94abb576b56c00206315f3074b9b89d (diff) |
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
-rw-r--r-- | perl6.html.markdown | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/perl6.html.markdown b/perl6.html.markdown index b5a25a41..54feeee7 100644 --- a/perl6.html.markdown +++ b/perl6.html.markdown @@ -193,6 +193,15 @@ sub mutate($n is rw) { 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`. # A sub itself returns a container, which means it can be marked as rw: |