Mixing Lingo statements with function values

If we are creating FVs from Lingo Expressions or Handlers we are free to mix them with Lingo handlers and statements like repeat, if, then, etc.
Care must be taken if you create FVs directly combining existing FVs with or without Free Variables (for lambda expression).
In this case you should be aware that you are composing FVs so everything that is not a FV will be directly invoked.
To illustrate what I mean let’s go through an easy example. We have previously defined the IsOdd Function. Let’s take a simplified version like this:
IsOdd = $.module._[2]
How can we define the IsEven function? There are many ways, you might think this is valid:
IsOdd = not $.module._[2]
But it isn’t
In this last code, not is not a Function Value, in order to compose FVs with not we have to “lambdamize” it.
A quick way to do it is with Lingo Expressions
fvNot = fun("x:not x")
IsOdd = fvNot $.module._[2]

Or we could have defined it as a handler and then either construct a function with fun or store it in a function module.
Actually not is already defined in Lingo module, I just wanted to show why we need to have the most basic functions already lambdamized (specially Lingo standard functions). Otherwise your first step in every project will be to define all this primitive FVs.

Leave a Reply

Security Code: