-
Notifications
You must be signed in to change notification settings - Fork 0
Functions
Bill Hails edited this page Aug 9, 2024
·
3 revisions
Anonymous functions can be created with the fn
keyword:
fn (x) { x * x };
Functions can be passed as variables, or immediately invoked as here:
fn (x) { x * x } (5); // 25
You can of course name your functions by assigning them:
factorial = fn (n) {
if (n == 0) {
1
} else {
n * factorial(n - 1)
}
}
The fn
keyword can take a function name, so:
fn factorial(n) {
if (n == 0) {
1
} else {
n * factorial(n - 1)
}
}
is completely equivalent.
Next: Closure
CEKF(s) a.k.a. F Natural a.k.a F♮