WriteStream en Smalltalk
Arma un string sin concatenación repetida.
"A WriteStream builds a string without repeated concatenation."
| report |
report := WriteStream on: String new.
report
nextPutAll: 'DAILY DOCKET';
cr;
nextPutAll: '3 jobs, ';
print: 545;
nextPutAll: ' sheets'.
Transcript show: report contents; cr.
"streamContents: wraps the same pattern in one expression."
Transcript show: (String streamContents: [:s |
#('set' 'ink' 'pull') do: [:step | s nextPutAll: step]
separatedBy: [s nextPutAll: ' / ']]); cr.
Cómo funciona
WriteStream on: String newabre el constructor.nextPutAll:agrega;print:formatea números adentro.streamContents:envuelve el patrón en una expresión.
Palabras clave y builtins usados aquí
new
El intento, en números
- Líneas
- 16
- Caracteres a escribir
- 454
- Tokens
- 78
- Ritmo de tres estrellas
- 55 tpm
Al ritmo de tres estrellas de 55 tokens por minuto, este intento toma unos 85 segundos.
Paso 1 de 2 en Streams; paso 24 de 31 en Fundamentos del lenguaje.