typestar

Cascades in Smalltalk

One receiver, many messages: the semicolon.

"A cascade sends several messages to one receiver: the semicolon."
| tray |
tray := OrderedCollection new.
tray add: 'em quad'; add: 'en quad'; add: 'thin space'.

Transcript
    show: 'Tray holds ';
    show: tray size printString;
    show: ' sorts';
    cr.

"yourself answers the receiver, not the last message's result."
tray := (OrderedCollection new add: 'ampersand'; yourself).
Transcript show: tray first; cr.

How it works

  1. add: ...; add: ... sends each add to the same collection.
  2. A cascade on Transcript builds a line in pieces.
  3. yourself answers the receiver instead of add's return.

Keywords and builtins used here

The run, in numbers

Lines
14
Characters to type
402
Tokens
56
Three-star pace
60 tpm

At the three-star pace of 60 tokens a minute, this run takes about 56 seconds.

Type this snippet

Step 1 of 3 in Messages & blocks, step 4 of 31 in Language basics.

← Previous Next →