Stefan Lidman writes:
> So, I must ask, what does this do:
>
> > sub foo() {
> > return my $self = {
> > print "Block";
> > return $self;
> > }
> > }
>
> > my $block = foo;
> # = sub {print "Block"; return $self;}
>
> A6:
> One obvious difference is that the sub on closures is now optional,
> since every brace-delimited block is now essentially a closure. You
> can still put the sub if you like. But it is only required if the
> block would otherwise be construed as a hash value; that is, if it
> appears to contain a list of pairs.
Um, yeah, but just a little farther down:
Although we say the sub keyword is now optional on a closure, the
return keyword only works with an explicit sub. (There are other
ways to return values from a block.)
And to clarify:
sub indexof(Selector $which, [EMAIL PROTECTED]) {
for zip(@data, 0...) -> $_, $index {
when $which { return $index }
}
}
Which actually creates a closure (well, in theory at least) on line 2
for the for loop, but the return inside of it returns from indexof.
Which is actually very, very nice.
So the question is: What happens when indexof isn't on the call chain,
but that inner closure is?
Luke
> > print "Main";
> > $block();
> > print "End";
>
> >That is, the block returns from a function that's not currently
> >executing.
>
> Main
> Block
> End
>
> is my guess.
>
> /Stefan