develooper Front page | perl.perl6.language | Postings from August 2001

Re: explicitly declare closures???

Thread Previous | Thread Next
Dave Mitchell
August 22, 2001 02:35
Re: explicitly declare closures???
Message ID:
Paul Johnson <> wrote:
> Actually, foo() is not a closure.  A closure is an anonymous subroutine
> and foo() clearly has a name.

Damain's definition of a closure includes named subs:

"In Perl, a closure is just a subroutine that refers to one or more lexical
variables declared outside the subroutine itself" - OO perl, p 56.

> Now, if you were proposing that named subroutines should behave like
> closures in this regard, which is what Piers and probably most others
> were expecting, I suspect that you would probably get broad agreement.

I'm not sure I understand this bit - named subs are really no different from
anon subs in respect to closures, except that named subs get instantianted
once - at compile time, and anon subs may get instantiated multiple
times, thus creating multiple private copies of the outer lexicals.
But once you throw in BEGIN and eval, the distinction starts to blur.

Dave M

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About