From 06216f24c9d1bf30137f54b12abe59b67acfdc2e Mon Sep 17 00:00:00 2001 From: b-xor-a <43441509+b-xor-a@users.noreply.github.com> Date: Thu, 4 Jul 2019 14:28:52 +0300 Subject: Fixed behavior of postfix ++ The postfix ++ operator increments its argument but returns its old value. --- perl6.html.markdown | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/perl6.html.markdown b/perl6.html.markdown index cb64b646..6b0df0d4 100644 --- a/perl6.html.markdown +++ b/perl6.html.markdown @@ -247,11 +247,12 @@ concat3(|@array); #=> a, b, c ## arguments. If you really need to, you can ask for a mutable container by ## using the `is rw` trait: sub mutate( $n is rw ) { - $n++; + $n++; # postfix ++ operator increments its argument but returns its old value } my $m = 42; -mutate $m; #=> 43 +mutate $m; # the value is incremented but the old value is returned + #=> 42 say $m; #=> 43 ## This works because we are passing the container $m to the `mutate` sub. -- cgit v1.2.3