GNU Smalltalk User's Guide
4.1.5 Math in Smalltalk
In this case, what happened was that the object
Integer), received a
+ message with an argument of
(also an Integer). The
+ message for integers then caused
Smalltalk to create a new object
16 and return it as the
resultant object. This
16 object was then given the
printNl message, and printed
16 on the terminal.
Thus, math is not a special case in Smalltalk; it is
done, exactly like everything else, by creating objects, and
sending them messages. This may seem odd to the Smalltalk
novice, but this regularity turns out to be quite a boon:
once you've mastered just a few paradigms, all of the language
"falls into place". Before you go on to the next
chapter, make sure you try math involving
- (subtraction), and
/ (division) also. These
examples should get you started:
(8 * (4 / 2)) printNl !
(8 - (4 + 1)) printNl !
(5 + 4) printNl !
(2/3 + 7) printNl !
(2 + 3 * 4) printNl !
(2 + (3 * 4)) printNl !