typestar

Temporaries and assignment in Smalltalk

Declare between bars, assign with :=, chain right to left.

"Temporaries declare between bars; := assigns; ^ answers."
| fontName pointSize leading |
fontName := 'Caslon'.
pointSize := 12.
leading := pointSize + 2.

Transcript show: fontName, ' set at ', pointSize printString; cr.
Transcript show: 'Leading: ', leading printString, ' points'; cr.

"Assignment chains right to left."
pointSize := leading := 14.
Transcript show: 'Both now ', pointSize printString; cr.

How it works

  1. | fontName pointSize leading | declares three at once.
  2. := assigns; = is reserved for asking equality.
  3. pointSize := leading := 14 chains from the right.

Keywords and builtins used here

The run, in numbers

Lines
12
Characters to type
408
Tokens
56
Three-star pace
65 tpm

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

Type this snippet

Step 2 of 3 in Values, step 2 of 31 in Language basics.

← Previous Next →