Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re^3: Why is the execution order of subexpressions undefined?

by dragonchild (Archbishop)
on Apr 12, 2005 at 12:34 UTC ( [id://446955]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Why is the execution order of subexpressions undefined?
in thread Why is the execution order of subexpressions undefined?

I personally agree with you that the order of subexpression evaluation could be defined in all cases, within Perl. (Heck, I think it could be defined now within C, as well.) But, I think tye has a very good point - who's going to go through the work of defining them? I certainly don't want Larry, Damian, Alison, or anyone on the P6L team doing it for P5. Maybe, this could be your big contribution to P6, but I'd get Larry's signoff on it, first. (Or, at the very least, run it past him and hope he doesn't deep-six the idea.)
  • Comment on Re^3: Why is the execution order of subexpressions undefined?

Replies are listed 'Best First'.
Re^4: Why is the execution order of subexpressions undefined?
by BrowserUk (Patriarch) on Apr 12, 2005 at 13:04 UTC

    As far as I can tell from how my thinking on the problem has gone, there is only one situation where execution order can affect the outome of a statement. That can be summarised as:

    Any statement where a single variable is referenced twice or more, and where one of the references is as an lvalue and the lvalue reference come before another reference, can be subject to an evaluation order dependancy.

    The major culprits from what I can divine/remember are autoincrement and autodecrememt, but it obviously includes assignment.

    I think that the rule I suggested to Tye, that subexpressions are evaluated first; then precedence order; then left to right within precedence order. pretty much covers the entire definition.

    But I also think that defining that parenthesised subexpressions will always be evaluated before the expressions they form a part of, and that multiple subexpressions will be evaluated left to right is the major part. Indeed, I think that this reflects current practice, and that defining it would simply formalise that. There may be exceptions, but I am not aware of any--yet! :)

    This formalisation would allow the programmer to define the order in which they want compound expressions to be evaluated and place the responsibility firmly upon their shoulders--but give them the tool to get it right, for sure.

    I haven't gotten to do much with pugs yet, but maybe it will fall out of that.


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    Lingua non convalesco, consenesco et abolesco.
    Rule 1 has a caveat! -- Who broke the cabal?

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://446955]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (4)
As of 2024-04-25 15:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found