Números en Smalltalk
Las fracciones quedan exactas; los enteros crecen sin límite.
"Numbers answer messages; fractions stay exact."
Transcript show: (17 / 4) printString; cr.
Transcript show: (17 / 4) asFloat printString; cr.
Transcript show: (17 // 4) printString, ' rem ',
(17 \\ 4) printString; cr.
"Fractions are first-class: a third plus a sixth is a half."
Transcript show: (1/3 + (1/6)) printString; cr.
Transcript show: 2 sqrt printString; cr.
Transcript show: (120 gcd: 340) printString; cr.
Transcript show: 10 factorial printString; cr.
Transcript show: (255 printStringBase: 16); cr.
Cómo funciona
17 / 4responde la fracción 17/4, no 4.25.//y\\dividen y toman el resto.10 factorialyprintStringBase: 16simplemente funcionan.
El intento, en números
- Líneas
- 13
- Caracteres a escribir
- 514
- Tokens
- 99
- Ritmo de tres estrellas
- 60 tpm
Al ritmo de tres estrellas de 60 tokens por minuto, este intento toma unos 99 segundos.
Paso 3 de 3 en Reflexión; paso 28 de 31 en Fundamentos del lenguaje.