On Fri, Nov 02, 2001 at 03:41:02PM -0500, Jeff 'japhy' Pinyan wrote:
> On Nov 2, Paul Johnson said:
>
> >3. Currently, Perl exhibits some surprising behaviour in certain
> > situations when a named subroutine is being used as a closure. In
> > practice, Perl does not properly close named subroutines. Most
> > people holding an opinion consider this a bug, although there is not
> > general consensus, and it is difficult to fix anyway. There are no
> > such caveats when using anonymous subroutines as closures.
>
> What are the problems with named subroutines being used as closures?
> Could you provide some test cases?
Probably not the most suitable subject for a beginners list, but for
those following along at home, what does this output?
[ filter this message through perl -x ]
#!/usr/bin/perl
{ my $a = "foo"; sub foo { sub { $a } } }
{ my $a = "bar"; sub bar { $a; sub { $a } } }
print foo()->(), "\n";
print bar()->(), "\n";
__END__
Congratulations if you got it right. To prove it wasn't just a lucky
guess, explain why :-)
> >4. Ideally, I would like to see both Perl and its documentation patched
> > such that named subroutines can be safely used as closures. There
> > are probably but a handful of people capable of doing that, and so
> > far it has not been done.
>
> We'll see.
I'll keep an eye out for your patch ;-)
--
Paul Johnson - [EMAIL PROTECTED]
http://www.pjcj.net
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]