Modules and lambdas

Module and Lambda are both used to organize expressions to express business logic. Athough they can both organize expressions, they are very different.

Lambda is usually used to describe an algorithn or business logic. By invoking lambda's : with some input parameters, then a calculation is output.

Module is a bit different in that it not only has sereral Lambdas, but also data. And often, these lambdas work around that data.

Lambda

(|{parameter}...|{expression}...)

Here {para} and {expression} can both be optinal.

(||) # an empty lambda #

(|| 1 2) # foo lambda just return `2` #

(|i j| 1 2) # foo lambda with 2 parameters valued `nil` #

(|(i = 2) j| 1 2) # foo lambda's parameter i has default value `2` #

By default, the default value of each parameter is nil, you can also define the default value yourself. When the parameter does not specify a value at the time of the call, the default value will take effect.

Predefined variables

variables
selfThe lambda generated closure (context).
argsA list of copy of arguments in lambda context.
lambdaThe lambda that generated current context.

Invoking

Lambda has the invoking method :. You just execute it like this

(puts: "here" "are" "parameters")

Module

Modules are those *.aqr files (or compiled *.aqrc) loaded from the file system.

(String: 1 2 3)

Predefined variables

variables
selfThe module generated closure (context).
argsA list of copy of arguments in module context.

Export

In a module, you can use an capital variable refered to a lambda, which will be exproted to outside world. Any non-lambda variables won't be detected outside module.