User Functions
User functions can be defined as follows:
my_func = {x, y =>
x + y
};
my_func.(2, 4) // returns 6
You see that the calling of a function is different than built-ins functions. It uses the .
operator to call the function.
Variables outside the function can be used inside the function.
GLOBAL = 15;
my_func = {x =>
GLOBAL + x
};
my_func.(4) // returns 19
Even currying it implemented.
factory = {x =>
{ y => x + y }
};
generated_function = factory.(4);
generated_function.(12) // returns 16
Also simple recursion works:
factorial = {n =>
if((n == 0) or (n == 1), 1, n * factorial.(n-1))
};
factorial.(8) // returns 40320