diff options
author | b-xor-a <43441509+b-xor-a@users.noreply.github.com> | 2019-07-04 14:28:52 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-07-04 14:28:52 +0300 |
commit | 06216f24c9d1bf30137f54b12abe59b67acfdc2e (patch) | |
tree | df8a5d812abb4fc3afe702328b49e2c91d16c488 | |
parent | 84cb0e88995b6d2f04a119cc25a695a33e1cbf9f (diff) |
Fixed behavior of postfix ++
The postfix ++ operator increments its argument but returns its old value.
-rw-r--r-- | perl6.html.markdown | 5 |
1 files 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. |