Strings y símbolos en Smalltalk
Los strings son colecciones; los símbolos, nombres internados.
"Strings are collections; symbols are unique interned names."
| title |
title := 'letterpress broadside'.
Transcript show: title asUppercase; cr.
Transcript show: (title copyReplaceAll: 'broad' with: 'bed'); cr.
Transcript show: (title indexOf: $b) printString; cr.
Transcript show: title reversed; cr.
"A symbol equals itself everywhere; strings only by content."
Transcript show: (#pressRun == #pressRun) printString; cr.
Transcript show: ('run' = 'run') printString; cr.
Transcript show: #broadside printString; cr.
Cómo funciona
copyReplaceAll:with:reescribe;reversedinvierte.indexOf: $bhalla la posición de un carácter.- Los símbolos comparan con
==— un objeto por nombre.
El intento, en números
- Líneas
- 13
- Caracteres a escribir
- 520
- Tokens
- 75
- Ritmo de tres estrellas
- 60 tpm
Al ritmo de tres estrellas de 60 tokens por minuto, este intento toma unos 75 segundos.
Paso 1 de 3 en Strings; paso 18 de 31 en Fundamentos del lenguaje.