Re: 3.0.3
- Posted by Pete Lomax <petelomax at blueyonder.co.uk> May 12, 2007
- 720 views
Derek Parnell wrote: > > Jeremy Peterson wrote: > > > > Juergen Luethje wrote: > > > > > > global constant > > > FALSE = 0, > > > TRUE = not FALSE > > Why not just > > > > TRUE = 1 > > Because it removes implementation dependancies. > It is generally accepted <snip> 'FALSE' is implemented as zero; some > implementations of 'TRUE', use 1, some -1, and some every non-zero value. > By defining 'TRUE' as 'not FALSE' it will work with any implementation. FWIW I prefer this, which I got from someone on this forum:
constant TRUE=(1=1), -- for Eu, 1 (aka <>0) FALSE=(1=0) -- for Eu, 0
It is succinct and programming-language-independent. > Also due to a quirk in the way that short-circuit IF evaluations work, it > can be made to execute faster when the conditions are separated out ... > > }}} <eucode> > global constant > FALSE = 0, > TRUE = not FALSE > > global type boolean (object x) > if not integer(x) then return FALSE end if > if x = FALSE return TRUE end if > if x = TRUE return TRUE end if > return FALSE > end type > </eucode> {{{ Crikey! I really (really!) thought that
if integer(x) and (x=FALSE or x=TRUE) then return TRUE end if return FALSE
would be faster, but you are right and in my first test some 35% faster. I thought I understood this, what is this "quirk" am I missing? Regards, Pete