if (x > 0) { //do something }then the compiler has to handle the "if" construction. The equivalent in Smalltalk is all message-based:
x > 0 ifTrue: ["do something"]Here you are sending the message > to x with argument 0; that returns a boolean. You then send the boolean the message ifTrue: with a block of code as an argument. The boolean will then either tell the block of code to evaluate itself, or do nothing, depending on whether it is a True or a False.
1 to: 10 do: [:z| Transcript cr; show: z asString]On the Number class there is a to:do: method defined, which looks like this:
to: aNumber do: aBlockSo that invokes the to:by:do method, which looks like this:
^self to: aNumber by: 1 do: aBlock
to: aNumber by: interval do: aBlockwhileFalse: is a method defined on a block, which uses a VM primitive - evaluate the second block until the result of evaluating the first one is true. Similarly, value: is a method defined on a block which uses a VM primitive meaning "evaluate this one-argument block using the argument passed into the value: method as the block's argument".
| current |
current := self.
[current = aNumber] whileFalse:
[aBlock value: current.
current := current + interval]