On Fri, Mar 14, 2003 at 09:59:42PM -0500, Uri Guttman wrote:
> well, this is what will be supported which is named nested subs.
> it looks to be compiled but callable only from within the outer sub and
> it has access to the outer subs vars.
>
> my $c;
> sub foo() {
> my $a;
> my $b;
>
> my sub bar() {
> $b = $a + $c;
> }
>
> bar();
> }
>
> is that close enough?
I think it's absolutely fine, assuming that &bar is a real closure
that can be returned or passed to other functions. I think nested
subs should default to "my", since there's no other point in using
them, but if Larry likes the "my", it can stay.
A6 implied to me that this would not be the case, because it only
used the word "closure" in connection with anonymous subs. But if
you can assure me that the above will work, I can sleep peacefully.
... well, just to be sure, here are a couple test cases:
my foo() {
my sub helper1() { ... helper2() ... $a ...}
my sub helper2() { ... helper1() ... $a ...}
my $a;
helper1();
}
helper1 and helper2 should be mutually recursive and enclose $a, ie
when compiling helper1 it shouldn't bind helper2() and $a to
whatever's in the outer/global scope.
my foo() {
... helper() ...
my $a;
my sub helper { ... $a ... }
}
The call to helper() should work and $a should be enclosed (of
course, it will be undef when helper() is called, but helper can set
it). It's often nice to put the helpers at the end--and note that
this cannot be achieved with the Perl 5 glob trick.
Andrew
_______________________________________________
Boston-pm mailing list
[EMAIL PROTECTED]
http://mail.pm.org/mailman/listinfo/boston-pm