December 22, 2024
Answer to Q3
myAccount balance: (myAccount balance) - 100 / 2 * 5
The message answer returned is myAccount.
The value of balance is 1000.
Explanation.
Evaluating brackets first, results in myAccount balance returning the number
object 500.
Reading left to write, binary before keyword, means that Smalltalk sends the
number object 500 the binary message - 100. This returns the number object
400 that will in turn be the receiver of another binary message / 2. This
returns the number object 200.
200 now receives the binary message * 5 and this returns the number object
1000.
1000 is passed as the argument to the keyword selector balance:
and myAccount
receives the keyword message balance: 1000.
Finally myAccount returns itself as the message answer. ( The textual representation
of this message answer is an Account)
Back to « Basic Questions on Precedence
⇑ Up to top of page