summaryrefslogtreecommitdiffhomepage
path: root/perl6.html.markdown
diff options
context:
space:
mode:
authorsamcv <samantham@posteo.net>2016-10-18 09:59:13 -0700
committerven <vendethiel@hotmail.fr>2016-10-18 18:59:13 +0200
commit0d11887c222ca23ec3f4a50e46fd36de6e568942 (patch)
tree5cbdc2b3b964d1875bad5533c2b1336b73720a37 /perl6.html.markdown
parentc08ca5b9c94abb576b56c00206315f3074b9b89d (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
Diffstat (limited to 'perl6.html.markdown')
-rw-r--r--perl6.html.markdown9
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: