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.
There should be no colon after the predicate (i.e., after the "b").
VMs are usually inlining those message sends, which makes them fast.
Thanks! I've now fixed this in the post.