It's not a complicated or extravagant request:If I understand your request -- in terms of the OP that started this thread -- you would like to be able to write something like this:Please make the language definition such that the compiler will do things in a predictable, defined sequence so that I the programmer can choose how I want them done. Even if the result is a tny weeny bit less efficient than it might be--which it never will be in Perl.
and have it produce a consistent result every time, which is always equivalent to one of the following:my $rv = func( $i, ++$i, $i+2 );
Obviously, we can't have it both ways. I'm not enough of a language design expert to speculate on how hard it might be implement the kind of ordering definition you seem to be looking for; let alone how hard it might be to document (i.e. clearly explain for programmers of various skill levels) what the chosen ordering turns out to be for all the kinds of situations where this is an issue.# either this: $rv = func( $i, $i+1, $i+2 ); $i++; # or this: $rv = func( $i, $i+1, $i+3 ); $i++;
But the problem for me is that the initial expression, taken by itself without an external rule of interpretation, is inherently ambiguous. Whichever rule is chosen to make this statement unambiguous, it will be a relatively arbitrary choice. And I'll need to see and understand the documentation for it in order to figure out what that initial expression is really doing. (update: either that, or else I'll just have to experiment with it to see what it does)
The same issue comes up for me in cases where execution order is already well defined, like $i*$j/$k*$l; -- sure, evaluation is simply left-to-right, and most languages are the same in this regard, so nobody should have any trouble with this. But I would still prefer to place the terms in an order that would be unambiguous regardless of the EO rules, and/or add some parens just to be sure. It's a small price to pay for clarity, given that the language is intended as much for human readers as for machines.
So my objection to your request is: why add arbitrary rules to the language, if the intent is simply to provide a consistent result for ambiguous expressions? IMHO, it would be better to be clear about what constitutes ambiguity in the language, and avoid it.
In reply to Re^19: Why is the execution order of subexpressions undefined?
by graff
in thread Why is the execution order of subexpressions undefined?
by BrowserUk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |