develooper Front page | perl.perl5.porters | Postings from December 2017

Re: [perl #132537] possible documentation error in perldata

Thread Previous
From:
Dan Book
Date:
December 14, 2017 17:04
Subject:
Re: [perl #132537] possible documentation error in perldata
Message ID:
CABMkAVUOTeXC1nz+tdKCOAgD8Gjn5whgY-T4qG+CUaYfpcYYrw@mail.gmail.com
On Sat, Dec 9, 2017 at 11:11 PM, Christoph Anton Mitterer <
calestyo@scientia.net> wrote:

> On Fri, 2017-12-08 at 01:12 -0800, Dave Mitchell via RT wrote:
> > It does by definition:
> > No, in scalar context, there isn't a list; instead there is merely
> > a sequence of comma operators (which return their RH argument), with
> > parentheses added for the purpose of precedence.
>
> That's at least not how the text in perldata or perlop does it make
> look like.
> It's rather written as it's still a list (and it even says, that all
> elements are actually evaluated), just that it doesn't "return" the
> whole list, but rather only it's last element.
>
>
> - (x, y, z) seems to be clearly what is defined to be a list, every
>   beginner will consider it as such, regardless of its context
> - other text places say that in both contexts (scalar/list) all
>   elements are evaluated, just that in scalar context everything but
>   the last is discarded
>
> So conceptually it still seems to be a list, and then the text that I
> was mentioning is still ambiguous...
> People would think (by operator precedence):
> 1. evaluation of the x, y, z (i.e. the list)
>    and the text says always in list context
> 2. for list context   = return all evaluated elements as a list
>    for scalar context = return only the last element (which would
>    however, by the documentation, be evaluated in list context, which
>    it is not.


The definition of 'list' in perl is more precise than that. In scalar
context x, y, z (with or without parentheses) is not a list, it is instead
a sequence of expressions like in C. They are evaluated in order and then
the last one is returned.

-Dan

Thread Previous


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