>>>>> "AP" == Andrew Pimlott <[EMAIL PROTECTED]> writes:
AP> On Fri, Mar 14, 2003 at 09:59:42PM -0500, Uri Guttman wrote:
>>
>> my $c;
>> sub foo() {
>> my $a;
>> my $b;
>>
>> my sub bar() {
>> $b = $a + $c;
>> }
>>
>> bar();
>> }
>>
>> is that close enough?
AP> I think it's absolutely fine, assuming that &bar is a real closure
AP> that can be returned or passed to other functions. I think nested
AP> subs should default to "my", since there's no other point in using
AP> them, but if Larry likes the "my", it can stay.
i don't see why you would want to return a named closure when you can
return an anon one. the implication (to me) of a named one is that it
can be called inside foo() directly and it has access to foo() variables
on the stack. those vars are not copied to a private pad for bar() like
a anon closure would do. they are different animals IMO.
AP> ... well, just to be sure, here are a couple test cases:
AP> my foo() {
AP> my sub helper1() { ... helper2() ... $a ...}
AP> my sub helper2() { ... helper1() ... $a ...}
AP> my $a;
AP> helper1();
AP> }
AP> helper1 and helper2 should be mutually recursive and enclose $a, ie
AP> when compiling helper1 it shouldn't bind helper2() and $a to
AP> whatever's in the outer/global scope.
you don't return a sub there rather you made a call to it. so it is not
the same as p5 closures. that should work fine but it doesn't need pads
and local copies of $a in helper1/2().
also that can be done with a plain block surrounding two subs. no need for
nesting subs there. show me a case where you need named nesting subs and
you return one of them to the outside.
AP> my foo() {
AP> ... helper() ...
AP> my $a;
AP> my sub helper { ... $a ... }
AP> }
AP> The call to helper() should work and $a should be enclosed (of
AP> course, it will be undef when helper() is called, but helper can set
AP> it). It's often nice to put the helpers at the end--and note that
AP> this cannot be achieved with the Perl 5 glob trick.
this is a compiler issue as to whether it can handle foward
references. if you declared helper with a signature first (of course
inside foo()), it would work for sure. i am not sure otherwise.
my point is that nested named subs are supported but they are not the
same as anon closures returned from an outer sub. but who knows what
larry would want there. i will ask on p6l.
uri
--
Uri Guttman ------ [EMAIL PROTECTED] -------- http://www.stemsystems.com
----- Stem and Perl Development, Systems Architecture, Design and Coding ----
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
Damian Conway Perl Classes - January 2003 -- http://www.stemsystems.com/class
_______________________________________________
Boston-pm mailing list
[EMAIL PROTECTED]
http://mail.pm.org/mailman/listinfo/boston-pm