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

Re: explicitly declare closures???

Thread Previous | Thread Next
From:
Dave Mitchell
Date:
August 22, 2001 02:35
Subject:
Re: explicitly declare closures???
Message ID:
200108220934.KAA11079@gizmo.fdgroup.co.uk
Paul Johnson <paul@pjcj.net> 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


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About