typestar

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

  1. 17 / 4 responde la fracción 17/4, no 4.25.
  2. // y \\ dividen y toman el resto.
  3. 10 factorial y printStringBase: 16 simplemente 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.

Escribe este fragmento

Paso 3 de 3 en Reflexión; paso 28 de 31 en Fundamentos del lenguaje.

← Anterior Siguiente →