5.6: Cascaded Messages
- Page ID
- 39596
Pharo offers a way to send multiple messages to the same receiver using a semicolon (;). This is called the cascade in Pharo jargon. It follows the pattern: expression msg1; msg2
.
Transcript show: 'Pharo is '. Transcript show: 'fun '. Transcript cr.
is equivalent to:
Transcript show: 'Pharo is'; show: 'fun '; cr
Note that the object receiving the cascaded messages can itself be the result of a message send. In fact, the receiver of all the cascaded messages is the receiver of the first message involved in a cascade. In the following example, the first cascaded message is setX:setY
since it is followed by a cascade. The receiver of the cascaded message setX:setY:
is the newly created point resulting from the evaluation of Point new
, and not Point
. The subsequent message isZero
is sent to that same receiver.
Point new setX: 25 setY: 35; isZero >>> false
Important
expression msg1. expression msg2
is equivalent to expression msg1; msg2
.