When the Float
is selected, the wide text pane prints: “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 is not a random number. It is 210 then written in base 2 :
10000000000, it is also 1 << 10
:
2^10 ⇒ 1024 1024 printStringBase: 2 ⇒ '10000000000' 1 << 10 ⇒ 1024
Therefore, to multiply an integer by 1024, we shift left of 10 its digits:
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
The system returns the error ZeroDivide
, division by zero.
(52/10) + (9/10) - (61/10) ⇒ 0 (52/10) + (7/10) + (11/100) ⇒ 601/100 soit 6.01 (12/10) * 3 - (36/10) ⇒ 0
There are different options, with slightly different results:
'There are 12 apples' select: [:i |i isLetter]. ⇒ 'Thereareapples'
Not really satisfying. So another option:
'There are 12 apples' select: [:i |i isDigit not]. ⇒ 'There are apples'
Or even a shorter option with the #reject:
message:
'There are 12 apples' reject: [:i |i isDigit]. ⇒ 'There are apples'
In String
, search for the method category format, there
you find the format:
method:
'Joe bought {1} apples and {2} oranges' format: #(5 4) ⇒ 'Joe bought 5 apples and 4 oranges'
The SpaceWar
, CentralStar
and SpaceShip
definitions with their added instance variable should look like:
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.