1: #line 942 "./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;
1: -1 2: 0 3: 1 4: -1 5: 0 6: 1 7: -1 8: 0 9: 1
The conditional expression is merely a shortcut for a match, as shown in the third sign function.