Compiler edit 895 adds new functions:
IFE(expr1,expr2{,flags})
IFE$(expr1$,expr2${,flags})
Without the flags parameter, these act as follows:
IFE(expr1,expr2) ! if expr1 then expr1 else expr2
IFE$(expr1$,expr2$) ! if expr1$ # "" then expr1$ else expr2$
The optional flags are defined in ashell.def and may be used to alter the type of test performed on the first expression:
|
|
|
---|---|---|
IFE_NB |
0 |
IFE$() default (test if expr1$ "Not Blank") |
IFE_NZB |
1 |
Treat "0" same as blanks |
IFE_TRUE |
0 |
IFE() default (test if expr1 TRUE) |
IFE_FALSE |
2 |
Test if expr FALSE (zero) instead of TRUE |
For example:
IFE(expr1,expr2,IFE_FALSE) ! if expr1 = 0 then expr1 else expr2
IFE$(expr1$,expr2$,IFE_NZB) ! if expr1$ # "0" and expr1$ # "" then expr1$ else expr2$
Note that consistent with the way A-ShellBASIC tests for string equality, trailing blanks are not significant.
IFE() and IFE$() are similar to the IFELSE() and IFELSE$() functions, except:
• | Whereas IFELSE/IFELSE$ uses a separate relative expression argument to decide which of the two possibilities to return, IFE/IFE$ uses the first expression both as the test expression and as a return value (if the test passes). |
• | Unlike IFELSE() and IFELSE$() which always evaluates each of the arguments, IFE() and IFE$() do not evaluate the second expression unless the test on first expression fails (i.e. unless the second expression is to be returned.) This is particulary useful when the second expression is a function call or other complex expression with significant overhead and/or side effects.) |