Re: short-circuiting

new topic     » goto parent     » topic index » view thread      » older message » newer message

> 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

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu