Reference

Forms Reference

Every kernel and surface form, organized by category. Click any form for its full documentation in the book.

Bindings

bind

Immutable binding → const

(bind name "Flavoparmelia caperata")

bind with type

Typed binding with runtime check

(bind :number x (parse input))

cell

Mutable container → { value: x }

(bind count (cell 0))

swap! · reset! · express

Cell operations

(swap! count (fn (:number n) (+ n 1)))
(reset! count 0)
(express count) ;; → current value

Functions

func

Named function → function

(func add
  :args (:number a :number b)
  :returns :number
  :body (+ a b))

fn · lambda

Anonymous function → arrow / lambda

(fn (:number x) (* x 2))

func multi-clause

Dispatch by type

(func describe
  (:args (:string x) :body ...)
  (:args (:number x) :body ...))

:pre · :post

Design by contract

(func withdraw
  :args (:number amount)
  :pre (> amount 0)
  :body ...)

Types & Matching

type

Algebraic data type

(type Option
  (Some :any value)
  None)

match

Exhaustive pattern matching

(match opt
  ((Some v) (use v))
  (None (fallback)))

match structural

Pattern match on plain objects

(match response
  ((obj :ok true :data d) d)
  (_ (handle-error)))

obj

Object literal with keywords

(obj :name "Flavoparmelia caperata"
     :age 42)

Control Flow

if

Conditional

(if (> x 0) "positive" "non-positive")

if-let · when-let

Conditional binding

(if-let (result (find-user id))
  (render result)
  (show-404))

for-of · for-in · for

Iteration

(for-of item items
  (console:log item))

try · catch · finally

Exception handling

(try
  (risky-op)
  (catch e (handle e))
  (finally (cleanup)))

Threading & Composition

-> · ->>

Thread first / thread last

(-> x (f) (g) (h))
;; → (h (g (f x)))

some-> · some->>

Nil-safe threading

(some-> user
  (:address)
  (:city)
  (:to-upper-case))

assoc · dissoc · conj

Immutable updates

(assoc user :name "New")
(dissoc user :temp)
(conj items new-item)

import · export

ES Modules

(import "./lib.js" (add))
(export (bind x 42))

Async & Interop

async · await

Async functions

(async (func fetch-data
  :body
  (bind res (await (fetch url)))
  (await (res:json))))

js: namespace

Escape to raw JS operations

(js:typeof x)
(js:eq x null)
(js:eval "1 + 2")