Skip to main content

# 3.3: Message Sends


There are three kinds of messages in Squeak.

1. Unary messages take no argument. 1 factorial sends the message factorial to the object 1.
2. Binary messages take exactly one argument. 1 + 2 sends the message + with argument 2 to the object 1.
3. Keyword messages take an arbitrary number of arguments. 2 raisedTo: 6 modulo: 10 sends the message consisting of the message selector raisedTo:modulo: and the arguments 6 and 10 to the object 2.

Unary message selectors consist of alphanumeric characters, and start with a lower case letter.

Binary message selectors consist of one or more characters from the following set:

+--/\*∼<>=@%|& ?,


Keyword message selectors consist of a series of alphanumeric keywords, where each keyword starts with a lower-case letter and ends with a colon.

Unary messages have the highest precedence, then binary messages, and finally keyword messages, so:

2 raisedTo: 1 + 3 factorial → 128


(First we send factorial to 3, then we send + 6 to 1, and finally we send raisedTo: 7 to 2.) Recall that we use the notation expression $$\rightarrow$$ result to show the result of evaluating an expression.

Precedence aside, evaluation is strictly from left to right, so

1+2*3 → 9


not 7. Parentheses must be used to alter the order of evaluation:

1+(2*3) → 7


Message sends may be composed with periods and semi-colons. A period-separated sequence of expressions causes each expression in the series to be evaluated as a statement, one after the other.

Transcript cr.
Transcript show: 'hello world'.
Transcript cr


This will send cr to the Transcript object, then send it show: 'hello world', and finally send it another cr.

When a series of messages is being sent to the same receiver, then this can be expressed more succinctly as a cascade. The receiver is specified just once, and the sequence of messages is separated by semi-colons:

Transcript cr;
show: 'hello world';
cr


This has precisely the same effect as the previous example.

This page titled 3.3: Message Sends is shared under a CC BY-SA 3.0 license and was authored, remixed, and/or curated by Andrew P. Black, Stéphane Ducasse, Oscar Nierstrasz, Damien Pollet via source content that was edited to the style and standards of the LibreTexts platform; a detailed edit history is available upon request.

• Was this article helpful?