"Even numbers are objects in Smalltalk. There is no special syntax for
manipulating numbers other than the literal forms of numbers.
For example, evaluating '1 + 2' results in the object 1 being sent the
message '+' with the single argument 2. The '+' method returns the
object 3.
An object is either a subclass of Number (in which case it is a number)
or it's not. An instance of String is not a number, though it might
contain the literal form of a number.
So let's say we have an instance of class String which we think might
contain a number in some form or other..."
|result|
result := '123.45' isNumber. "false is assigned to result. '123.45' is
a String, not a Number."
result := 123.45 isNumber. "true is assigned to result. 123.45 is
indeed a number."
result := Number readFrom: ('123.45' readStream). "result is the
Fraction(!) 2469/20"
result := result asFloat. "result is now the Float 123.45"
result := Number readFrom: ('this is not a number' readStream). "result
is the Integer zero."
result := Number readFrom: ('123abc' readStream). "result is the Integer
123"
result := 'This is not a number' isNumeric. "result is false"
result := '123' isNumeric. "result is true"
result := '123abc' isNumeric. "result is false"
result := '123' asNumber. "result is the Integer 123"
|number result|
number := '123' asNumber.
result := number isInteger. "result is true"
result := number isRational. "result is true"
number := 123 / 456. "result is the Fraction 41/152"
result := number isInteger. "result is false"
result := number isRational. "result is true"
"Other tests that all Number objects respond to are:
>>isFinite
>>isInfinite
>>odd
>>positive" |