Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re^5: Pre vs Post Incrementing variables

by BrowserUk (Patriarch)
on Sep 13, 2010 at 03:45 UTC ( [id://859936]=note: print w/replies, xml ) Need Help??


in reply to Re^4: Pre vs Post Incrementing variables
in thread Pre vs Post Incrementing variables

You did, or rather the passage you quoted. The expressions whose order of evaluation is not defined are those that are operands.

Okay. I see where you are coming from. You think that you know better what the authors of that passage meant when they wrote it, than they did. "They" being Kernighan & Ritchie in "Appendix A:The C reference Manual" of "The C Programming Language".

That explains a great deal.


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
  • Comment on Re^5: Pre vs Post Incrementing variables

Replies are listed 'Best First'.
Re^6: Pre vs Post Incrementing variables
by ikegami (Patriarch) on Sep 13, 2010 at 05:42 UTC

    You think that you know better what the authors of that passage meant when they wrote it, than they did.

    Because I know something by another name, I think I know better than someone else? That makes no sense. Your post is naught but slander.

      Because I know something by another name

      That doesn't wash either.

      1. In this: f( 1 , 2 );, The constants 1 & 2 are the operands of the comma operator.
      2. But in this: f( 1+2 , 3+4 ),

        the operands of the comma operator are the results of the subexpressions: 1+2 and 3+4.

        Ie. The operands of the comma operator are the values 3 & 7.

      By analogy, in this: f( ++$n , ++$n ), the operands of the comma operator should be the results of the preincrement subexpressions.

      Not two references to $n after both sub-expressions have been evaluated.

      As for your ploy of resorting to meta-argument to distract from the argument, I'm going to ignore it this time, just like I did last time. And the time before...


      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.

        the operands of the comma operator should be the results of the preincrement subexpressions.

        Correct. And it does. For good or bad, the result of preincrement is the variable that was incremented. We've covered that you wish it wasn't. I don't disagree.

        Not two references to $n after both sub-expressions have been evaluated.

        Correct. It doesn't. It returns $n after the first preincrement has been evaluated and $n after the second preincrement has been evaluated. Like I said earlier, the evaluation order is already what you would expect it to be.

        use 5.010; # say use Data::Alias; sub f { say @_; } $n=3; f(++$n, 0+$n, ++$n); $n=3; do { local @_; alias $_[0] = ++$n; alias $_[1] = 0+$n; alias $_[2] = ++$n; &f; };
        545 545

        As for your ploy of resorting to meta-argument to distract from the argument

        "You think that you know better what the authors of that passage meant when they wrote it, than they did." is not an argument.

        Update: Improved example.

        By analogy, in this: f( ++$n , ++$n ), the operands of the comma operator should be the results of the preincrement subexpressions.
        By the same logic in f($n) f should be passed the result (value) of $n, disallowing f from modifying $n.

        Perl doesn't work that way.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (2)
As of 2024-04-24 23:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found