Functions

You can declare anonymous function with the following syntax:

// no params
fn { body }

// 1 param
fn x { body }

// 3 params
fn x, y, z { body }

Function are a first-class citizen, meaning that they are treated as a regular value. As a consequence, they can be assigned to values, passed as function arguments, or returned from functions.

For this reason, there is no concept of "named function", but you can assign them to variables using let declarations

let identity = fn x {
  x
}

identity(42) // => 42

You can use functions and let declarations together to archive recursion, which is the only looping mechanism in the language. Tail calls are optimized to have a O(1) stack usage, so you can safely recur without incurring in a stack overflow.

And finally, you can use lexical closures like in any other language:

let add_curried = fn a {
  fn b { a + b }
}

add_curried(1)(2) // => 3