Kalandra

Learn

Functions and pipes

A functional language for parallel and distributed programming. The next chapter of Clio.

Declare a function with fn, followed by its name and parameters. Call it by writing the function and its arguments separated by spaces. Parentheses group expressions; they are also useful when a call is an argument to another call.

Compose calls

A pipe written as -> passes a value to the next function. In this example, 10 flows through double and then addThree. The result is 23.

A function can return another function. addOffset returns add, which remembers offset from its enclosing call. These ordinary closures run in the current execution environment; they cannot be transferred directly to a parallel worker.

main.kalandra

kalandra
fn double n: n * 2

fn addOffset offset:
  fn add n: n + offset
  add

export fn main:
  addThree = addOffset 3
  10 -> double -> addThree

Expected result:

text
23

Try in playground

Keep grouping explicit

Use parentheses when combining calls, arithmetic, or comparisons if you are uncertain about grouping. Some historical expression-binding behavior is deliberately preserved while the port is completed.

Next: arrays and maps