Fluxon Docs
Guide

Functions

Declaring functions with `fn`, returns, calling without parentheses, and lambdas.

A function is declared with fn. Arguments are separated by spaces (no commas):

fn add a b
  ret a + b

Single-line function

If the body is a single expression, you can write it on one line with ->:

fn double x -> x * 2

Return

Two ways, but they give the same result:

  • ret x — explicit return
  • The last expression is returned automatically (without ret)
fn add a b
  a + b            # the last expression — returned automatically

fn check x
  if x > 0
    ret "positive"   # ret is needed for an early return
  "non-positive"     # the last expression

Note

ret is used only when you need an early (mid-function) return. At the end — just write the expression.

ret also works inside a lambda. This matters most in HTTP handlers. Instead of a deep if/elif/else pyramid for validation, write a guard clause (early exit) — the code stays flat:

# ❌ Deep nesting (bad):           ✅ Guard clause (good):
http.on :post "/x" \req ->        http.on :post "/x" \req ->
  if req.body.email                 if !req.body.email
    if req.body.body                  ret rep 400 {error:"email required"}
      rep 201 (...)                 if !req.body.body
    else                              ret rep 400 {error:"body required"}
      rep 400 {...}                 rep 201 (db.ins "t" {...})
  else
    rep 400 {...}

Calling a function

Arguments are separated by spaces, without parentheses:

add 2 3            # → 5
double 4           # → 8

Parentheses are only needed for grouping (passing the result of one function into another):

double (add 2 3)   # first add 2 3 = 5, then double 5 = 10

A no-argument function is called with empty parentheses (). Since a call without parentheses is defined by its arguments, this is the only way to call a function that has no parameters. This clearly distinguishes a name (value) from a call:

fn new_id -> rand.str 8
new_id()           # CALL → a new random id each time
new_id             # NOT a call → the function VALUE (for callback/reg)

f(x) (argument inside parentheses) does not work — the canonical form is f x. Empty () is only for a no-argument call (one task = one way).

Lambda (anonymous function)

With the \ character, used inline:

\x -> x * 2
each_map nums \x -> x * 2    # multiply each element by 2

On this page