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

Re: Operator precedence

by ikegami (Pope)
on Jan 13, 2013 at 21:21 UTC ( #1013131=note: print w/ replies, xml ) Need Help??


in reply to Operator precedence

There's no such thing as priority, and neither precedence nor associativity define the order in which stuff is evaluated. They determine what is an operand of what operator.

apple && (banana || cherry) apple: LHS operand of && banana || cherry: RHS operand of && banana: LHS operand of || cherry: LHS operand of || (apple && banana) || cherry apple && banana: LHS operand of || apple: LHS operand of && banana: RHS operand of && cherry: RHS operand of ||

Operand evaluation order is what controls the order in which stuff is evaluated.

In order to provide short-circuiting, && evaluates its LHS operand before its RHS. Same goes for ||.

Given

apple && (banana || cherry) apple: LHS operand of && banana || cherry: RHS operand of && banana: LHS operand of || cherry: LHS operand of ||

apple must be evaluated before banana || cherry
banana must be evaluated before cherry

So we get:

  1. apple
  2. banana
  3. cherry
  4. ||
  5. &&

Given

(apple && banana) || cherry apple && banana: LHS operand of || apple: LHS operand of && banana: RHS operand of && cherry: RHS operand of ||

apple && banana must be evaluated before cherry
apple must be evaluated before banana

So we get:

  1. apple
  2. banana
  3. &&
  4. cherry
  5. ||


Comment on Re: Operator precedence
Select or Download Code
Re^2: Operator precedence
by muba (Priest) on Jan 18, 2013 at 22:43 UTC

    It took me a good couple days to realise what you meant with "There's no such thing as priority, and neither precedence nor associativity define the order in which stuff is evaluated. They determine what is an operand of what operator."

    But I get it now. Looking at it that clarifies a lot. Thank you.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (7)
As of 2014-12-25 18:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (161 votes), past polls