How to? Shortcut evaluation

  • This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.
#1
Is there any way to achieve shortcut evaluation of logical expressions?

E.g. iff not isfile abc .or. %@fileage[abc] gt 12345 then...

runs into an error if file "abc" doesn't exist.
 
#2
Is there any way to achieve shortcut evaluation of logical expressions?

E.g. iff not isfile abc .or. %@filesize[abc] gt 12345 then...

runs into an error if file "abc" doesn't exist.
I presume what you mean is to evaluate a logical expression left-to-right, and STOP when the result is known? AFAIK that would require a major redesign of the parser.
 
#5
Not really feasible unless I remove support for the boolean operations, as the parser can't tell whether you might reverse the condition somewhere later in the evaluation.
Excluding the .XOR. operator, wouldn't reversing the result of a test already performed require that it be within parentheses? But I see the other major parsing issue: IIRC variable expansion is performed before anything else, thus in the OP's example the attempt to evaluate %@fileage[abc] would fail before the "isfile abc" test is performed.

When I come across a compound test such as in the OP, where the result of one of the tests determines whether or not a second test can be validly performed, I use nested IF/IFF tests; and I may need to perform Boolean manipulations to get them in the proper order. Auxiliary variables may be need, too.

unset x
if isfile abc if not %@filesize[abc] GT 12345 set x=no
iff not defined x then ...

It is more complicated than in some other programming languages, but it's all that can be done...
 
May 31, 2008
376
2
#6
not exactly what the OP asked for, but here's another idea, using do/leave as a glorified goto
Code:
do 1
  if %a == %b .and. %c == %d leave
  if %e != 32 .or. %f == A leave
  iff %something% then
    ...
    leave
  endiff
  gosub WHEN_ALL_CONDITIONS_FAIL
enddo