2.48. Lambda expressions

Felix allows a function to be specified in an expression; this is called a lambda expression:
Start felix section to tut/tutorial/tut-1.48-0.flx[1 /1 ]
     1: #line 4551 "./lpsrc/flx_tutorial.pak"
     2: //Check functions:anonymous
     3: //Check functions:lambda
     4: #import <flx.flxh>
     5: var x = 10;
     6: while
     7:   (fun ():bool = { return x>0; })
     8:   { print x; endl; x = x - 1; };
End felix section to tut/tutorial/tut-1.48-0.flx[1]
Start data section to tut/tutorial/tut-1.48-0.expect[1 /1 ]
     1: 10
     2: 9
     3: 8
     4: 7
     5: 6
     6: 5
     7: 4
     8: 3
     9: 2
    10: 1
End data section to tut/tutorial/tut-1.48-0.expect[1]
Of course, we have already used lambdas in the short form, by enclosing expressions in curly braces; this example shows the long form. Lambdas of course may have arguments:
Start felix section to tut/tutorial/tut-1.48-1.flx[1 /1 ]
     1: #line 4579 "./lpsrc/flx_tutorial.pak"
     2: //Check functions:anonymous
     3: //Check functions:lambda
     4: #import <flx.flxh>
     5: fun f(g:int->int,x:int) = { return g x; }
     6: print
     7: (
     8:   f
     9:   (
    10:     (fun(a:int):int = { return a + a; }),
    11:     1
    12:   )
    13: ); endl;
End felix section to tut/tutorial/tut-1.48-1.flx[1]
Start data section to tut/tutorial/tut-1.48-1.expect[1 /1 ]
     1: 2
End data section to tut/tutorial/tut-1.48-1.expect[1]