Re: Short-cut evaluation Question
- Posted by Travis Beaty <twbeaty at osage.net> Mar 01, 2004
- 371 views
Hello again! On Sunday 29 February 2004 02:47 pm, Juergen Luethje wrote: > Current Euphoria versions only use short-circuit evaluation in > conditions tested by "if", "elsif" or "while". I.e. if you want > short-circuit evaluation, write the code above like this: > > global type Widget(object o) > if not atom(o) then > return false > elsif (o = 0 or TypesMatch(o, "QWidget") or IsBaseClass(o, "QWidget")) > then return true > else > return false > end if > end type > > Regards, > Juergen Yes, your way of doing it does work. However, now I get warning messages that "call to TypesMatch() might be short-circuited." Hmm ... wouldn't this typically be the desirable outcome? I suppose the only time that it wouldn't be is in someone were depending upon a side effect, and such a place would be a rather bad place to do that, since Euphoria uses short-cut evaluation. I've opted for this rather wordy set up instead. global type Widget(object o) if not atom(o) then return false elsif o = 0 then return true else return (TypesMatch(o, "QWidget") or IsBaseClass(o, "QWidget")) end if end type It seems to work, and without warnings. As far as my previous set up ... return (o = 0 or TypesMatch(o, "QWidget") or IsBaseClass(o, "QWidget")) Why would short-cut evaluation not be a normal, or even "Good" thing in this instance? Cojabo: good point about the parenthesis. In this particular instance, that doesn't seem to help though. Travis W. Beaty Osage, Iowa. -- When asked the definition of "pi": The Mathematician: Pi is the number expressing the relationship between the circumference of a circle and its diameter. The Physicist: Pi is 3.1415927, plus or minus 0.000000005. The Engineer: Pi is about 3.