4 ms·
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
by dws 10y 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.
- i_feel_great 10y agoThere should be no colon after the predicate (i.e., after the "b").
- philippeback 10y agoVMs are usually inlining those message sends, which makes them fast.
- pozorvlak 10y agoThanks! I've now fixed this in the post.