in reply to A Romp Around addn

sub addn($n) { my $retsub = sub ($x) { $x + $n } return $retsub; }
So, in Perl 6, by the time it gets into the first set of curlies { my ... }, $n is already a copy of the argument passed in to addn() and not simply an alias?

No need to do the following?
sub addn($n) { my $m = $n; my $retsub = sub ($x) { $x + $m } return $retsub; }
I'm curious. Thanks.

Replies are listed 'Best First'.
Re^2: A Romp Around addn
by John M. Dlugosz (Monsignor) on Aug 18, 2008 at 05:01 UTC
    Thank you for finding that. $n is a read-only alias to the caller's value. I see your point: the original value might change, and that would affect the closure.

    However, you don't have to make a copy the way you show. Just change the parameter to pass-by-copy. I'll update the article.

    —John