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

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

Thread Previous | Thread Next
From:
Robin Barker
Date:
October 21, 2003 06:51
Subject:
RE: [perl #24250] "return" required in some anonymous closures
Message ID:
533D273D4014D411AB1D00062938C4D9040466EA@hotel.npl.co.uk
I found the follow bug today, I think it may be related to this one.

% perl5.8.1 -lwe 'sub a {} print main->a'
main
% perl5.8.0 -lwe 'sub a {} print main->a'

% perl5.8.1 -lwe 'sub a {return} print main->a'

% perl5.8.0 -lwe 'sub a {return} print main->a'


So when the method is empty rather than {return} in perl5.8.1 the object
is returned.

Robin

-----Original Message-----
From: Dave Mitchell [mailto:davem@fdgroup.com]
Sent: 21 October 2003 14:33
To: hv@crypt.org
Cc: 
Subject: Re: [perl #24250] "return" required in some anonymous closures


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."

-------------------------------------------------------------------
This e-mail and any attachments may contain confidential and/or
privileged material; it is for the intended addressee(s) only.
If you are not a named addressee, you must not use, retain or
disclose such information.

NPL Management Ltd cannot guarantee that the e-mail or any
attachments are free from viruses.

NPL Management Ltd. Registered in England and Wales. No: 2937881
Registered Office: Teddington, Middlesex, United Kingdom TW11 0LW.
-------------------------------------------------------------------

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