>>>>> "LP" == Luke Palmer <[EMAIL PROTECTED]> writes:
>> on boston.pm a thread arose about having named subs inside subs. of >> course perl5 can do it but they don't do anything useful but they do >> have some odd implemenation defined closure behavior. >> >> someone brought up lisp and scheme and how they do it (differently from >> each other). >> >> first point is that bar is NOT a closure. it makes no copies of $a and >> $b into a pad. bar uses the actual $a and $b of foo on the stack. it >> should do work the same for foo's params. LP> I might be misunderstanding you, but how is this different LP> (semantically) from a lexical named closure? LP> my $c; LP> sub foo() { LP> my $a; LP> my $b; LP> my sub bar() { LP> $b = $a + $c; LP> } LP> bar(); LP> } mea culpa. the thread in question implied that named nested subs wouldn't exist and i hadn't memorized apoc6 yet like the rest of you. :) but here is another question. in my view nested subs are not closures (in the classic p5 sense) in that they don't make local copies of the referenced lexicals into its private pad. they just access the parent's vars directly on its stack. and i don't see a reason to ever return a nested named sub to an outside caller. if you need to share static vars between nested subs and returned closures you can put those in an outer block wrapper like in p5. can someone come up with an useful example of returning a named nested sub? or even a case where you return a closure but also have nested subs? mind you i don't know if a closure can even call a nested sub unless it closes (copies) around it too. so my point is that anon closures and nested subs are not the same animal and aren't related much either. is that a reasonable statement? 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