New IFELSE Functions

Language enhancement (compiler edit 773) adds the built-in system functions:

IFELSE(cond, expr1, expr2)

IFELSE$(cond, expr1, expr2)

Each takes a conditional expression (cond) and two value expressions (expr1 and expr2). If the conditional expression evaluates to TRUE, then the function returns the value of expr1, else it returns the value of expr2. IFELSE returns a numeric value and IFELSE$ returns a string value.

These functions are conveniences which can often eliminate the need for a temporary variable or duplication of statements that differ only by a single either/or choice. For example, consider a case where you want to print a value with one of two masks depending on whether the value is less than 1. You might code it like this:

if VALUE >= 1 then

    PRINT VALUE USING "#####"

else

    PRINT VALUE USING "#.###"

endif

 

With the IFELSE$() function, you can eliminate the IF statement and reduce the two PRINT statements to one:

PRINT VALUE USING IFELSE$(VALUE>=1,"#####","#.###")

Or, in the case of larger statements where you are more likely to introduce temporary variables than to repeat variations of the statement, IFELSE() can eliminate the need for a temporary variable, e.g.

if flag'disable then

    CSTATE = MBST_DISABLE

else

    CSTATE = MBST_ENABLE

endif

xcall AUI, AUI_CONTROL, CTLOP_ADD, CTLID$, CTEXT$, CSTATE, CTYPE$, CMD$, FUNC$, ...

 

The above can be reduced to a single statement using IFELSE():

xcall AUI, AUI_CONTROL, CTLOP_ADD, CTLID$, CTEXT$, ifelse(flag'disable,MBST_DISABLE,MBST_ENABLE), CTYPE$, CMD$, FUNC$, ...