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

Re^3: eval order of args to a sub

by dewey (Pilgrim)
on May 30, 2007 at 19:30 UTC ( [id://618282]=note: print w/replies, xml ) Need Help??


in reply to Re^2: eval order of args to a sub
in thread eval order of args to a sub

Hmmm... I can't see where in Terms and List Operators (Leftward) the comma operator's order of evaluation is given... it mostly seems to concern term/parenthetical precedence. Am I missing something obvious?

Also, I don't understand your `update' remark. Your code produces 1 1, as I would have expected... could you clarify?

~dewey

Replies are listed 'Best First'.
Re^4: eval order of args to a sub
by Joost (Canon) on May 30, 2007 at 19:42 UTC

      You were looking at the wrong section of the document. If you check the Operator Precedence and Associativity table, you'll notice the list seperator is left-associative, and that operator associativity is defined as follows:

      Operator associativity defines what happens if a sequence of the same operators is used one after another: whether the evaluator will evaluate the left operations first or the right.

      I can confirm that is how it works on my system (ActivePerl 5.8.8 on WinXP).

        Mmm, that doesn't say what you think it says.

        "Operator associativity" defines what happens if a sequence of the same operators is used one after another: whether the evaluator will evaluate the left operations first or the right. For example, in "8 - 4 - 2", subtraction is left associative so Perl evaluates the expression left to right. "8 - 4" is evaluated first making the expression "4 - 2 == 2" and not "8 - 2 == 6".
        This answers the question "Which minus operator will be evaluated first?" But our question is different: "Will a given operator evaluate its left-hand or right-hand argument first?"

        In other words, what if the code were foo() - bar() - baz()? Will foo() execute before bar(), or the reverse? Operator associativity has nothing to say about that. This is the same issue as $i++ * $i and foo($i++, $i).

        I've looked through the docs, and it's not there. Perl doesn't define the evaluation order of subexpressions.

        I can confirm that is how it works on my system (ActivePerl 5.8.8 on WinXP).

        /me too. (Actually, that was in answer to otto.)

      I see. Thanks.

      ~dewey

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (7)
As of 2024-04-18 04:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found