in reply to Evaluation Order again.
While the operand evaluation order ("the execution order of subexpression") hasn't changed since you asked your earlier question, it's actually defined for many operators[1].
Your earlier question proposes the following expression as an example of where operand evaluation order is undefined:
my $rv = func( $i, ++i, $i+2 );
However, operand evaluation order is almost completely defined for that statement. Most relevant is the following passage from the documentation:
Binary "," is the comma operator. [...] In list context, it's just the list argument separator, and inserts both its arguments into the list. These arguments are also evaluated from left to right.
The only ambiguity is which of the addition's operands is evaluated first[2].
As for why the order is undefined for things such as addition? Probably because there's very little point in doing so. There's also the question of what criteria would be used to decided what would be ordered and in which order. Without having a reason to order, it's hard to know how it should be ordered. It's far better to leave the order as undefined as possible to provide the most flexibility should we ever add a feature that prefers lack of ordering or some ordering.
It's explicitly defined for the comma operator, logical operators and the flip-flop operators. It's implicitly defined for assignment operators. It's not defined for arithmetic operators, comparison operators and the range operators.
The only two possible orders consistent with the documentation are:
Update: Made clearer in response to the jerk's comment.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Evaluation Order again.
by oiskuu (Hermit) on May 30, 2016 at 20:03 UTC | |
by ikegami (Patriarch) on May 31, 2016 at 21:31 UTC | |
by oiskuu (Hermit) on Jun 01, 2016 at 08:21 UTC | |
by ikegami (Patriarch) on Jun 01, 2016 at 15:42 UTC | |
by oiskuu (Hermit) on Jun 01, 2016 at 17:48 UTC | |
| |
by rurban (Scribe) on Sep 21, 2016 at 14:35 UTC | |
by BrowserUk (Patriarch) on Sep 21, 2016 at 15:49 UTC | |
|
Re^2: Evaluation Order again.
by Tanktalus (Canon) on May 30, 2016 at 19:11 UTC | |
by ikegami (Patriarch) on May 30, 2016 at 19:22 UTC | |
by Tanktalus (Canon) on May 30, 2016 at 19:35 UTC | |
| A reply falls below the community's threshold of quality. You may see it by logging in. |