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

Re: explicitly declare closures???

Thread Previous | Thread Next
From:
Paul Johnson
Date:
August 22, 2001 13:16
Subject:
Re: explicitly declare closures???
Message ID:
20010821193925.H12169@pjcj.net
On Tue, Aug 21, 2001 at 06:06:06PM +0100, Dave Mitchell wrote:
> Piers Cawley <pdcawley@iterative-software.com> wrote:
> > > {
> > >     my $x = "bar";
> > >     sub foo {
> > > 	# $x  # <- uncommenting this line changes the outcome
> > > 	return sub {$x};
> > >     }
> > > }
> > > print foo()->();
> > 
> > Well, I would expect it to output 'foo' on both occasions, and I'm
> > more than a little surprised to discover that it doesn't. Looks like a
> > bug to me.
> 
> Using the notation $outer:x, $foo:x and $anon:x to refer to whatever
> $x might be in the 3 scopes:
> 
> With the $x:
> 
> foo() is a closure created at compile time.

Actually, foo() is not a closure.  A closure is an anonymous subroutine
and foo() clearly has a name.

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.

-- 
Paul Johnson - paul@pjcj.net
http://www.pjcj.net

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