December 22, 2024

Answer to Q1

 

Evaluating

10 - (17 -10)plus: 10

Answers with 13

Explanation

  1. Read left to right, brackets first. The nested expresssion (17 - 10) is evaluated first. This returns the number object 7
  2. Read left to right. A binary expression takes precedence over a keyword expresssion. Therefore the number object 10 receives the binary message - 7 where the argument 7 has been passed to the binary selector -from the previous expression evaluation.
  3. 10 - 7 returns the number object 3, which now becomes the receiver of the keyword message plus: 10
  4. Evaluating 3 plus: 10 returns the message answer 13

 

Back to « Basic Questions on Precedence

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Up to top of page