Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

How to? Shortcut evaluation

Jun
223
0
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.
 
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.
 
yup

Replaced @filesize[] with @fileage[] as the previous wouldn't bail out if the file in question doesn't exist.
 
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...
 
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
 
Back
Top
[FOX] Ultimate Translator
Translate