There are 3 different kinds of messages in Smalltalk (and Capytalk):
- a message with a receiver only and no arguments (unary): !x abs
- a message (composed of one or two non-alphabetic characters) with a receiver and a single argument (binary): 1 - !x
- a message with a receiver and one or more arguments (keyword): !KeyDown bpm: !BPM dutyCycle: 0.1
The order of evaluation (without parentheses) for messages is first unary, then binary, and finally keyword.
This means that !KeyDown bpm: !BPM dutyCycle: 1 - !x abs means:
- evaluate !x abs
- evaluate 1 - (!x abs)
- evaluate !KeyDown bpm: !BPM dutyCycle: (1 - (!x abs))
When using more than one keyword message in an expression you will always need to use parentheses:
(!KeyDown bpm: !BPM) triggerEvery: !Count
Without the parentheses, Smalltalk will be trying to send the message bpm:triggerEvery:, which is not defined.
If you are sending more than one unary (binary) message in a row, the order of evaluation is left to right. For example, !x abs negated is evaluated as (!x abs) negated and !KeyPitch + 24 / 48 is evaluated as (!KeyPitch + 24) / 48. This simple rule for binary expressions is different than the complex precedence rules you may have learned for arithmetic in other computer languages.