From 0d11887c222ca23ec3f4a50e46fd36de6e568942 Mon Sep 17 00:00:00 2001 From: samcv Date: Tue, 18 Oct 2016 09:59:13 -0700 Subject: [PATCH] =?UTF-8?q?Perl6:=20Explain=20that=20Integers=20Can't=20be?= =?UTF-8?q?=20Passed=20and=20Modified=20in=20Sub's=20Even=20If=20Using=20`?= =?UTF-8?q?is=20rw=C2=B4=20(#2471)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 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 --- perl6.html.markdown | 9 +++++++++ 1 file changed, 9 insertions(+) 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: