Cuando está seleccionado Float, el texto ancho muestra: “class
definition for Float ° 92 instance methods ° 34
class methods ° 1280 total lines of code”
0 to: Float twoPi by: 1/10 do: [:i | Transcript show: i cos; cr]
1024 no es un número aleatorio. Es 210, escrito en base 2:
10000000000, también es 1 << 10:
2^10 ⇒ 1024 1024 printStringBase: 2 ⇒ '10000000000' 1 << 10 ⇒ 1024
Por lo tanto, para multiplicar un número entero por 1024, desplazamos sus dígitos 10 posiciones hacia la izquierda:
360 << 10 ⇒ 368640 360 * 1024 ⇒ 368640
5.2 + 0.9 - 6.1 ⇒ 8.881784197001252e-16 5.2 + 0.7 + 0.11 ⇒ 6.010000000000001 1.2 * 3 - 3.6 ⇒ -4.440892098500626e-16
El sistema devuelve el error ZeroDivide, división por cero.
(52/10) + (9/10) - (61/10) ⇒ 0 (52/10) + (7/10) + (11/100) ⇒ 601/100 soit 6.01 (12/10) * 3 - (36/10) ⇒ 0
Hay diferentes opciones, con resultados significativamente distintos:
'There are 12 apples' select: [:i |i isLetter]. ⇒ 'Thereareapples'
Realmente no es satisfactorio. Por lo tanto otra opción:
'There are 12 apples' select: [:i |i isDigit not]. ⇒ 'There are apples'
O incluso una opción más corta con el mensaje #reject::
'There are 12 apples' reject: [:i |i isDigit]. ⇒ 'There are apples'
En String, busca la categoría de método format,
allí encontrarás el método format::
'Joe bought {1} apples and {2} oranges' format: #(5 4)
⇒ 'Joe bought 5 apples and 4 oranges'
Las definiciones SpaceWar, CentralStar y
SpaceShip con su variable de instancia añadida deberían tener el
siguiente aspecto:
Object subclass: #SpaceWar
instanceVariableNames: 'centralStar ships torpedoes'
classVariableNames: ''
poolDictionaries: ''
category: 'Spacewar!'
Object subclass: #CentralStar
instanceVariableNames: 'mass'
classVariableNames: ''
poolDictionaries: ''
category: 'Spacewar!'
Object subclass: #SpaceShip
instanceVariableNames: 'position heading velocity
fuel torpedoes mass acceleration'
classVariableNames: ''
poolDictionaries: ''
category: 'Spacewar!'
SpaceShip>>position ^ position SpaceShip>>velocity ^ position SpaceShip>>mass ^ mass
SpaceShip>>position: aPoint position := aPoint SpaceShip>>velocity: aPoint velocity := aPoint Torpedo>>heading: aFloat heading := aFloat
SpaceShip>>left "Rotate the ship to its left" heading := heading + 0.1 SpaceShip>>right "Rotate the ship to its right" heading := heading - 0.1
SpaceShip>>push "Init an acceleration boost" acceleration := 10 SpaceShip>>unpush "Stop the acceleration boost" acceleration := 0
CentralStar>>initialize super initialize. mass := 8000.