> 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).
> 
> well, i want to dredge up how PL/I did it and i think it makes for a
> useful concept.
> 
> my $c ;
> 
> sub foo {
> 
>       my $a ;
>       my $b ;
> 
>       blah
> 
>       bar() ;
> 
>       sub bar {
> 
>               $b = $a + $c ;
>       }
> }
> 
> 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.

I might be misunderstanding you, but how is this different
(semantically) from a lexical named closure?

    my $c;
    sub foo() {
        my $a;
        my $b;
    
        my sub bar() {
            $b = $a + $c;
        }

        bar();
    }

Bar can be recursive.  $a and $b still refer to foo()'s $a and $b.
Bar can even trivially have nested subs.  bar() can't be seen from
outside foo.  I don't see the difference. Perhaps you could give a
better example in how this differs?

Luke

Reply via email to