Skip to content

Functions

A function is a Closure value (tag: "Closure") that carries its parameters, optional rest parameter, body expression, and the environment of definition. Native built-ins are Native values with a JS implementation.

define

lisp
(define x 42)                  ; bind a value
(define (square n) (* n n))    ; bind a function — sugar for (define square (lambda (n) (* n n)))

lambda

lisp
(lambda (x y) (+ x y))            ; two parameters
(lambda x (apply + x))            ; rest parameter — x is a list of all args
(lambda (x . rest) (cons x rest)) ; one fixed + rest

Closure.params is the fixed parameter list; Closure.rest is the rest-parameter name when present.

Calling

lisp
(square 5)                  ; → 25
(apply + (list 1 2 3))      ; → 6
((lambda (x) (* x x)) 7)    ; → 49

Closures capture lexical scope

lisp
(define (make-counter)
  (define n 0)
  (lambda ()
    (set! n (+ n 1))
    n))

(define c (make-counter))
(c) (c) (c)                ; → 1, 2, 3

Each closure carries its env. Mutating n via set! updates the captured environment, not a fresh copy.

Higher-order functions

lisp
(map (lambda (x) (* x 2)) (list 1 2 3))  ; → (2 4 6)
(filter even? (list 1 2 3 4 5))          ; → (2 4)
(fold + 0 (list 1 2 3 4 5))              ; → 15

Many higher-order functions are SICP-flavored: map, filter, fold, for-each, reduce, compose, pipe. The full list lives in the hof package (run :help hof in the REPL).

Variadic / arity-aware

(arity proc) returns the procedure's arity. (procedure? v) tests for both Closure and Native. The runtime rejects calls with too few fixed arguments; rest-parameter procedures absorb extras into the rest list.

Oracle procedures

OracleProc is a procedure whose implementation is an LLM call. Construct one with make-oracle-proc:

lisp
(define summarize
  (make-oracle-proc
    (lambda (text)
      (effect infer.op (list "Summarize: " text) :model 'claude-sonnet))))

(summarize "long article ...")
;; → a Meaning value, not a string

The procedure has a policy digest that captures what the oracle is allowed to do — capabilities, budget, oracle request tags. OracleProc calls produce Meaning values, which preserve the LLM's output along with provenance.

See also

Source: projects/omega-lisp/src/core/eval/values.ts:725-728 (Closure, Native, OracleProc shapes), projects/omega-lisp/src/core/prims.ts (where the standard set of higher-order primitives is installed).