[newbie] Complex boolean value?

Bijan Parsia bparsia at email.unc.edu
Sun Jun 17 19:27:13 UTC 2001


--On Sunday, June 17, 2001 8:15 PM +0200 Frantisek Fuka 
<fuxoft at terminal.cz> wrote:

> Sorry about my stupid question but I started to experiment with Squeak
> yesterday and when I wanted to come up with Boolean expression to check
> if any of the 3 conditions is true, I came up with this:
>
> ((value < 1 or: [value > x1]) or: [value > x2])
>	 ifTrue: [self error: 'Invalid value'].
>
> It works, but it looks rather complex. How to do this more "cleanly",
> with less parentheses?

You could use | (and for #and:, &)
	(value < 1) | (value > x1) | (value > x2)
		ifTrue: [self error: 'Invalid value'].

Or parallel ifTrue:s
	value < 1 ifTrue: [self error: 'Invalid value'].
	value > x1 ifTrue: [self error: 'Invalid value'].
	value > x2 ifTrue: [self error: 'Invalid value'].

Yick. A code smell wafts for sure. However, it seems a bit of a weird set 
of tests to begin with.

Hope this helps.

Cheers,
Bijan Parsia.





More information about the Squeak-dev mailing list