develooper Front page | perl.perl5.porters | Postings from October 2003

Re: [perl #24250] "return" required in some anonymous closures

From:
Dave Mitchell
Date:
October 21, 2003 12:10
Subject:
Re: [perl #24250] "return" required in some anonymous closures
Message ID:
20031021190957.GA10005@fdgroup.com
On Tue, Oct 21, 2003 at 02:32:32PM +0100, Dave Mitchell wrote:
> On Tue, Oct 21, 2003 at 02:11:32PM +0100, hv@crypt.org wrote:
> > Dave Mitchell <davem@fdgroup.com> wrote:
> > :I provisonally propose the new syntax:
> > [...]
> > :ie roughly speaking
> > :
> > :    sub foo() : constant { $x + $y }
> > :
> > :is about equivalent to
> > :
> > :    sub foo() { $x + $y }
> > :    BEGIN {
> > :	my $val = foo();
> > :	no warnings 'redefine';
> > :	eval 'sub foo() { "' . $val . "}'
> > :    }
> > 
> > The biggest problem I see with that is this:
> >   future% perl -wle 'my $pi = 3; sub pi () : constant { $pi } print pi()'
> >   Use of uninitialized value in concatenation (.) or string at -e line 1.
> >   
> >   future%
> > 
> > I'm in at least two minds about how big a problem that actually is.

After more thought, I now think that :constant is unnecessary baggage;
my preferred solution for today is to add XS to constant.pm so that it
just efficently does lots of newCONTSUB()s without requiring any language
hooks.  The sub(){$lex} hack is quietly retired, and the standard
sub name {1} construct is kept for those who are emotionally attached to
it.

If any cleverer ways are devised of handling large numbers of imported
constants, a la POSIX, then Export.pm and/or constant.pm can be hacked
to accomodate them.

No doubt tomorrow, like the wind, I shall blow in a new direction...


-- 
This is a great day for France!
    -- Nixon at Charles De Gaulle's funeral



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