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
| fontName pointSize leading |declares three at once.:=assigns;=is reserved for asking equality.pointSize := leading := 14chains from the right.
Keywords and builtins used here
TranscriptcrprintString
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.
Step 2 of 3 in Values, step 2 of 31 in Language basics.