← Back to context

Comment by dws

8 years ago

The explanation is almost correct, but misses a tiny, but interesting detail. Subclasses of Boolean do implement #ifTrue: and #ifFalse:, wich each take a block (a no-argument function) as an argument. But they also implement #ifTrue:ifFalse:, which takes two blocks as arguments. In

    a < b:
        ifTrue: [...]
        ifFalse: [...]

a single message (#ifTrue:ifFalse:) is sent to the boolean that results from evaluating 'a < b'. A true, being the singleton instance of the True subclass of Boolean, evaluations the first argument and ignores the second. False has a singleton instance, false, that does the opposite.

Coming from Pascal and C, seeing that IF/ELSE could be implement without special syntax was a real mind warper.