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

RE: explicitly declare closures???

Thread Previous | Thread Next
From:
Garrett Goebel
Date:
August 28, 2001 07:27
Subject:
RE: explicitly declare closures???
Message ID:
71BEC0D4E1DED3118F7A009027B12028010BDFF4@EXCH_MISSION
From: Dave Mitchell [mailto:davem@fdgroup.co.uk]
> Ken Fox <kfox@vulpes.com> wrote:
> 
> > You're speaking in Perl implementation terms. I've already told you
> > that if Perl acts the way you say it does, then Perl has buggy
> > closures. You don't need to explain a bug to know that one exists!
> 
> Okay, to humour me for a mo', what should the following 2 examples
> output if Perl were doing the "right" thing?
> 
> 
> sub pr { print $_[0] || 'undef', "\n" }
> 
> { my $x = 'X'; sub f { $F = sub {pr $x} }}
> f(); $F->();
>
> { my $y = 'Y'; sub g { pr $y; $G = sub {pr $y} }}
> g(); $G->();

X
Y
Y

I'm hardly an authority, but a closure should reflect the environment at
runtime... not compile

You forgot the other example that someone raised:

{ my $x = 'X'; *h = sub { $H = sub {pr $h} }}
h(); $H->();

Which prints:

Z

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