develooper Front page | perl.perl5.porters | Postings from May 2012

Re: proposal: functional C<if>

Thread Previous | Thread Next
From:
Abigail
Date:
May 1, 2012 13:04
Subject:
Re: proposal: functional C<if>
Message ID:
20120501200530.GA19903@almanda
On Tue, May 01, 2012 at 03:53:49PM -0400, Eric Brine wrote:
> On Tue, May 1, 2012 at 11:24 AM, David Nicol <davidnicol@gmail.com> wrote:
> 
> > On Tue, May 1, 2012 at 10:11 AM, Paul LeoNerd Evans
> > <leonerd@leonerd.org.uk> wrote:
> > > At which point we might consider what
> > >
> > >  my @values = (while($cond) { EXPR });
> > >
> > > might do.
> > >
> > > Just a thought...
> >
> > it seems clear that @values would wind up holding one of undef, 0, '',
> > or some overloaded reference that gives a false value in boolean
> > context..
> >
> 
> It does not seem clear to me at all. Why would Perl do something useless? I
> would expect a warning if not an error.


I'd expect Perl to DWIM, and that's to populate @values with the successive
values of EXPR. That is, if it were valid syntax, I'd expect:

    my $i = 3;
    my @values = while ($i) {$i * $i --};
    say "@values";

to print out "9 4 1".

That would be much more useful than the final result of the condition.



Abigail

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