Characters in Smalltalk
$-prefixed objects with their own protocol.
"Characters are objects with a $ prefix and their own protocol."
| initial |
initial := $W.
Transcript show: initial asLowercase printString; cr.
Transcript show: initial isVowel printString; cr.
Transcript show: initial asInteger printString; cr.
"Strings answer character questions element by element."
Transcript show: ('Wren42' select: [:c | c isDigit]); cr.
Transcript show: ('drop cap' collect: [:c | c asUppercase]); cr.
Transcript show: (Character value: 63) printString; cr.
How it works
$Wis a Character;asIntegerreveals the code point.isVowelandisDigitanswer directly.- Strings select and collect over their characters.
Keywords and builtins used here
CharacterTranscriptasIntegerasLowercaseasUppercasecrisDigitisVowelprintString
The run, in numbers
- Lines
- 11
- Characters to type
- 484
- Tokens
- 76
- Three-star pace
- 60 tpm
At the three-star pace of 60 tokens a minute, this run takes about 76 seconds.
Step 2 of 3 in Strings, step 19 of 31 in Language basics.