develooper Front page | perl.perl5.porters | Postings from January 2016

Re: [perl #127391] possible inconsistency in "perlop" documentationon associativity of operators

Thread Previous | Thread Next
From:
Lukas Mai
Date:
January 27, 2016 21:45
Subject:
Re: [perl #127391] possible inconsistency in "perlop" documentationon associativity of operators
Message ID:
56A93A5F.3030009@gmail.com
Am 27.01.2016 um 17:32 schrieb Wolf-Dietrich Moeller (via RT):
> # New Ticket Created by  Wolf-Dietrich Moeller
> # Please include the string:  [perl #127391]
> # in the subject line of all future correspondence about this issue.
> # <URL: https://rt.perl.org/Ticket/Display.html?id=127391 >
>
>
> Hello,
> I am not sure if the following issue in the "perlop"-documentation needs
> clarification.
>
> In the section on "Operator Precedence and Associativity" there is the line:
> "right       = += -= *= etc. goto last next redo dump"
> The "etc." means to me that all other assignment operators are also
> right-associative, i.e. in particular also the short-circuit "&&=", "||="
> and "//=".
>
> Taking the explanation in the section on "Assignment Operators" (further
> below in perlop), the example given there for a "combined operator" can be
> extended to a sequence of operators with "&&=":
>      $y &&= $x += 2;  is equivalent to    $y = $y && ($x = $x + 2);
> Given the short-circuit behavior of '&&', it is clear that the assignment
> "($x = $x + 2)" in the "equivalent assignment" (right) is not executed if $y
> == 0 (and correctly the "simple" assignment '$y = ' is right-associative).

OK so far.

> But looking to the "original assignment" (left), where $y only appears to
> the left of the "&&=" operator, the (effective) associativity for this "&&="
> operator is "left".

I don't understand this at all. If &&= and += were left associative, 
then $y &&= $x += 2 would be parsed as ($y &&= $x) += 2, which is 
clearly not the case.

What do you mean by effective associativity?

-- 
Lukas Mai <plokinom@gmail.com>

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