Re: Short circuit question
- Posted by "Christian Cuvier" <Christian.CUVIER at agriculture.gouv.fr> Nov 18, 2003
- 435 views
> From: Robert Craig <rds at RapidEuphoria.com> > Subject: Re: Short Circuit Question > > > Daniel Kluss wrote: >> Can someone exlain why line to of the output actually tests both 1 and >> 3, shouldn't just test 1? >> is it interpreted as ((1 or 2) and 3) or as (1 or (2 and 3)) ? > > It's interpreted as ((1 or 2) and 3). > Since 1 is true, 1 and 3 are tested while 2 is skipped. > > I know that some languages give higher precedence > to "and" vs "or", but in Euphoria "and" and "or" > have the same precedence. I didn't want to have too many > different precedence levels. C has about 15 levels. > Euphoria has about half that. After a couple of decades > of programming in C, I still find myself checking the > book to confirm the precedence of some operators. > But this is not mere idiotism from those "other languages". It is more consistent with the math properties of thse logicals. Indeed, "or" behaves relative to "and" like addition does relative to multiplication: a and (b or c)=(a and b) or (a or c) (compare with a * (b + c) = (a * b ) + ( a * c ) ) For me, this is another confusing aspect of Eu that the relative precedences of "or" and "and" don't mirror those of '+' and '*'. I'm aware that it's much too late to change this, however. As C authorizes many unrelated operators to interact, it's quite natural to still check the manual for some unusual combinations :) . Regards CChris