1. Re: Short Circuiting
>>Isaac suggested something along the lines of (I'm paraphrasing):
>>
>>> try:
>>> if length( s ) > 2 then
>>> if compare( s[1..3], "EOF" ) = 0 then
>>> ... [alpha]
>>> else
>>> ... [beta]
>>> end if
>>> else
>>> [gamma]
>>> end if
>>
>>The problem with his example is that I'm stuck at [beta] when I want
>to
>be at
>>[gamma]. That's part of my complaint.
>
>I don't pretend to understand what you're trying to do entirely but
>wouldn't getting to [gamma] be as easy as removing the "esle"
>statement
>just before it. This way if the length of "s" is greater than 2 then
>either [alpha] or [betta] would be executed and then [gamma] would be
>executed regardless. Is this what you want?
No, he wants to do this:
if s[1..] is "EOF", then do alpha, else do beta, but slicing makes it
hard to do.
Actually, with this code, to get the correct result:
if find("EOF", s) then
... [alpha]
else
[gamma]
end if
Although this would give the wrong results if s = "eeeEOF", as opposed to
s = "EOFjkl", but given the context, seems pretty appropriate to me.
Yeah, yeah, I know this is supposed to be an example of hard code that
short-circuiting would make easier.... But....
The point is, a lot of times with Euphoria (or any language, for that
matter), one way may be long and require several lines of code and
redundancies, while a different one can be clearer, shorter, and simpler.
(Depending on what's going on.)
BTW, anyone who wants same(), (ie David) it would look like this (the
shortest method, 3 lines, 2 statements [AFAIK, "end function" isn't
counted as a seperate statement])
global function same(sequence s1, sequence s2)
return not compare(s1, s2) -- if equal return 1, otherwise return 0.
end function
_____________________________________________________________________
You don't need to buy Internet access to use free Internet e-mail.
Get completely free e-mail from Juno at http://www.juno.com
Or call Juno at (800) 654-JUNO [654-5866]