1.18. The Conditional Expression

Felix supports the conditional expression as shown:
Start felix section to tut/examples/tut_beg119.flx[1 /1 ]
     1: #line 750 "./lpsrc/flx_tutorial.pak"
     2: #import <flx.flxh>
     3: 
     4: fun sign1(x:int):int =
     5: {
     6:   return
     7:     if x < 0 then -1
     8:     else
     9:       if x == 0 then 0
    10:       else 1
    11:       endif
    12:     endif
    13:   ;
    14: }
    15: 
    16: print (sign1 (-20)); endl;
    17: print (sign1 0); endl;
    18: print (sign1 20); endl;
    19: 
    20: fun sign2(x:int):int =
    21: {
    22:   return
    23:     if x < 0 then -1
    24:     elif x == 0 then 0
    25:     else 1
    26:     endif
    27:   ;
    28: }
    29: 
    30: print (sign2 (-20)); endl;
    31: print (sign2 0); endl;
    32: print (sign2 20); endl;
    33: 
    34: 
    35: fun sign3(x:int):int =
    36: {
    37:   return
    38:     match x < 0 with
    39:     | case 1 => -1 // true
    40:     | case 0 =>    // false
    41:       match x == 0 with
    42:       | case 1 =>  0 // true
    43:       | case 0 =>  1 // false
    44:       endmatch
    45:     endmatch
    46:   ;
    47: }
    48: 
    49: print (sign3 (-20)); endl;
    50: print (sign3 0); endl;
    51: print (sign3 20); endl;
    52: 
    53: 
End felix section to tut/examples/tut_beg119.flx[1]
In the conditional construction, one or more elif clauses may be give, however the else clause is required. The elif clause is used reduce the need for terminating endif keywords.

The conditional expression is merely a shortcut for a match, as shown in the third sign function.