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

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

From:
Yitzchak Scott-Thoennes
Date:
October 21, 2003 12:55
Subject:
Re: [perl #24250] "return" required in some anonymous closures
Message ID:
20031021195452.GA3076@efn.org
On Tue, Oct 21, 2003 at 08:09:57PM +0100, Dave Mitchell <davem@fdgroup.com> wrote:
> 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.

That doesn't sound like something to do for 5.8.2 if released in a few
weeks.  How doable would it be to give a warning for "const" padsv
anon subs, and just have constant.pm turn off the warning?
 
> No doubt tomorrow, like the wind, I shall blow in a new direction...



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