On 10/7/05, Juerd <[EMAIL PROTECTED]> wrote:
> Luke Palmer skribis 2005-10-07 15:31 (-0600):
> > sub foo($x) {
> > sub bar() {
> > return $x;
> > }
> > return &bar;
> > }
> > foo(42).(); # ????
>
> Does this mean that this Perl 5 snippet no longer does the same in Perl 6?
>
> {
> my $foo = 5;
> sub bar {
> return $foo;
> }
> }
Uh no. Okay, when I said that they "don't close", I guess I meant
they don't close like anonymous routines do. It works precisely like
Perl 5's:
sub foo {
my $foo = 5;
sub bar {
return $foo;
}
return \&bar;
}
I don't think I've ever seen that used in Perl 5. Closing over that
$foo doesn't mean anything. That's why we're allowing "my" before
such declarations now, so that they can close over something useful.
Luke