Re: short-circuiting
- Posted by Don <eunexus at yahoo.com> Jun 02, 2004
- 560 views
> I haven't used euphoria for a while, and have just got back into it. Quick > question > about short-circuiting a function: > from memory euphoria allowed this to short-circuit...? but does not work > however > > > function test(object whatever) > return (sequence(whatever) and (length(whatever) = 4)) > end function > > test(0) errors because it goes on to call length(), however this code: > > > int test(int whatever) { > if ((++whatever == 1) && (++whatever == 2)) { > } > return whatever; > } > > prints 1 as expected. > > so how do I achieve the same logic in euphoria? Well, the documentation is quite clear: "Euphoria does short-circuit evaluation of if, elsif, and while conditions involving and and or" Cant do this in a return statement... But you can do this as a substitute function test(object whatever) if not sequence(whatever) then return 0 else return length(whatever) = 4 end if end function constant Val = test(0) Don Phillips National Insturments mailto: eunexus at yahoo.com