Lambda Expressions
Finally we go into LingoF Lambda Expressions. This method is the same as combining functions but introducing free variables.
Because LingoF is implemented over Lingo we will start to suffer some syntax overhead from now on. The first one is that we will have to explicitly initialize Free Variables. We do so with the Var shortcut:
x = var()
Now we can combine functions as before plus we can combine them with free variables. To define a function with free variables we will use (yes, you already guessed) the fun shortcut.
The syntax will be: fun( {free var 1} , {free var 2} , … , {free var n} ) [{function body}]
add2 = fun(x) [ add [2] [x] ]
At this point you should ask why do I need to define it that way. I was able to do it before this way:
add2 = add [2]
The answer is both definitions are equivalent, they express the same computation but the latter is expressed as point free style. While there is a big discussion about which style is convenient, my personal approach is always try to use point free style until it affects readability.
Let’s go back to our IsOdd function. How can we define it, without creating new handlers or Lingo Expressions?
Without lambda expressions it was:
IsOdd = $.IfThenElse._["yes"]["no"] .@ [ $.modulo._[2] ]
Now using lambda expressions it can be written as
x = var()
IsOdd = fun(x) [ $.IfThenElse [ $.modulo [x][2] ] ["yes"]["no"] ]
Which one do you prefer?