Navigation:  Appendix A: Jumping Into Smalltalk >

Messages

Previous pageReturn to chapter overviewNext page

Smalltalk has three kinds of messages.

Type

Form

Parameters

Examples

unary

alphanumeric starting with a lowercase letter

0

squared

binary

punctuation marks

1

+

keyword

multiple colon terminated alphanumeric words

1 or more

do:

between: and:

To pass one or more parameters, you would usually use a keyword message. Each parameter is preceded by a keyword. Smalltalk doesn't use brackets and commas to separate the parameters.

Examples

Java

Smalltalk

myAccount.getBalance();

myAccount getBalance

myAccount.setBalance (10);

myAccount setBalance: 10

myAccount.transfer (20, anotherAccount)

myAccount transfer: 20 to: anotherAccount

myAccount.equals (anotherAccount);

myAccount = anotherAccount

Order of operations is:

Unary (evaluate first)
Binary (evaluate second)
Keyword (evaluate last)
 
Within each priority level, evaluate left to right.

Java

Smalltalk

3 + 5 * 6 // answer: 33

3 + 5 * 6 "answer: 48"

Notice that in the Smalltalk version, this expression is actually two messages:

Message 1
receiver: 3
message: +
parameter: 5
 
result: 8

Message 2
receiver: 8
message: *
parameter: 6
 
result: 48