typestar

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

  1. $W is a Character; asInteger reveals the code point.
  2. isVowel and isDigit answer directly.
  3. Strings select and collect over their characters.

Keywords and builtins used here

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.

Type this snippet

Step 2 of 3 in Strings, step 19 of 31 in Language basics.

← Previous Next →