Language reference

Literals

SyntaxTypeExample
-?[0-9]+:i3242, -7
-?[0-9]+i64:i641000i64
0x…:i320xFF
-?[0-9]*\.[0-9]+:f323.14
'c':i32'A' → 65, '\n' → 10
"…":String"hello"

Core forms

defn — function definition

(defn add (a :i32 b :i32) :i32
  (+ a b))

defmacro — compile-time macro

(defmacro when (cond body)
  (if cond body 0))

Variadic macros use ...rest:

(defmacro my-macro (fixed ...rest)
  ...)

deftype — struct definition

(deftype Point (x :i32) (y :i32))

Auto-generates: Point/x, Point/y (getters) and Point/x!, Point/y! (setters).

defop — operator overload

(defop + "i32.add" (:i32 :i32) :i32)

defstatic — static string data

(defstatic greeting "hello\n")

Use with (static-ptr greeting) and (static-len greeting).

let — local binding

(let x :i32 42
  (printf "%d\n" x))

set! — local assignment

(set! x (+ x 1))

if — conditional

(if (= x 0) "zero" "nonzero")

while — loop

(while (< i n)
  (set! i (+ i 1)))

drop — discard value

(drop (some-function))

as — type cast

(as :i32 ptr)