1. Re: Short Circuiting
Lewis had suggested on:
>> if length( s ) > 2 then
>> if compare( s[1..3], "EOF" ) = 0 then
>> ... [alpha]
>> else
>> ... [beta]
>> end if
>> elsif ...
>> [gamma]
>> elsif
>> [delta]
>> else
>> [epsilon]
>> end if
to remove the 'else', so gamma would always be exectuted. The problems
here are:
The constraint was for [gamma] to be executed only if [alpha] is not.
The issue was that the additional test meant that the code ended up at
[beta], where I didn't want it to go.
2. Further, there may be other elsifs to perform (amended example), so
moving the logic of [gamma] to [beta] is not practical.
My point (again) is NOT to say that these cases cannot be solved. I was
trying to point out that the requirement to test ranges before testing
values often leads to convoluted test, and that perhaps a better
solution than short-circuiting would be to offer some 'safer' routines.
-- David Cuny
-- for anyone who cares, here's a way ugly solution.
-- it breaks the if into multiple if..end if's, and
-- uses a flag to cause only one block to be executed
-- i've used this for some of my giant case statements,
-- such as in a multi-line editor.
flag = 1
if length( s ) > 2 then
if compare( s[1..3], "EOF" ) = 0 then
flag = 0
... [alpha]
end if
end if
if flag and ... then
flag = 0
[beta]
end if
if flag and ... then
flag = 0
[gamma]
end if
elsif flag and ... then
flag = 0
[delta]
end if
if flag then
[epsilon]
end if