Caracteres en Smalltalk
Objetos con prefijo $ y protocolo propio.
"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.
Cómo funciona
$Wes un Character;asIntegerrevela su código.isVoweleisDigitresponden directo.- Los strings hacen select y collect sobre sus caracteres.
El intento, en números
- Líneas
- 11
- Caracteres a escribir
- 484
- Tokens
- 76
- Ritmo de tres estrellas
- 60 tpm
Al ritmo de tres estrellas de 60 tokens por minuto, este intento toma unos 76 segundos.
Paso 2 de 3 en Strings; paso 19 de 31 en Fundamentos del lenguaje.