Who needs operator precedence, anyway?

Bert Freudenberg bert at impara.de
Tue Dec 21 18:38:55 UTC 2004


Puzzle of the day: Why do these conditionals work as intended even 
without parentheses?

{true. false} do: [:a |
	0 to: 1 do: [:b |
		a = true & b = 0 ifTrue: [Transcript cr; show: 'case 1'].
		a = true & b = 1 ifTrue: [Transcript cr; show: 'case 2'].
		a = false & b = 0 ifTrue: [Transcript cr; show: 'case 3'].
		a = false & b = 1 ifTrue: [Transcript cr; show: 'case 4'].
	]
]

Hint: (scroll down after trying to figure it out yourself)





































Hint: Look up the implementation of &

- Bert -




More information about the Squeak-dev mailing list