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 06:32
Subject:
Re: [perl #24250] "return" required in some anonymous closures
Message ID:
20031021133231.GC7867@fdgroup.com
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.

Well, it's better than the current behaviour because you don't even get a
constant at the moment:

./perl -wle 'my $pi = 3; sub pi () { $pi } print pi; $pi++; print pi;'
3
4

-- 
"Emacs isn't a bad OS once you get used to it.
It just lacks a decent editor."



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