Objects and messages

In Smalltalk everything is about communication between objects, manifested by sending messages to objects. Messages are synchronous, meaning, that the program does not continue unless it received a response to the messages sent out.

anObject messageWithParameter: param.     " anObject is an object and receives the message messageWithParameter: with a parameter named param, which itself is an object "

The above code is a complete command: it states the receiver (anObject), the message to pass (messageWithParameter:) and the parameter to pass (param). IMPORTANT: A command ends with a dot '.' to indicate the end of the message list.

We can also pass messages, which do not take any parameter:

anObject justDoSomething.     " anObject is the receiver of the message justDoSomething. There is no parameter being passed "

We can force the order of the evaluation of the parameters by grouping the message passing with brackets:

anObject msg1: ((anotherObject msg2:param) doSomething).     " the innermost command is evaluated, the message doSomething sent to it, the resulting evaluation passed to object anObject via the message msg1: "

By default, the order of evaluation is left to right.

moltalk@moltalk.org      version of this document: V3.0