Operator reference

Primitive operatives and applicatives ship with the runtime; the standard library (kernel.scm / promises.scm) is loaded by the REPL, scripts, and packages. Kind badges: operative unevaluated operands · applicative args evaluated first · library defined in Scheme.

Core evaluation

vau

operative

(vau formals envarg body …)

Constructs an operative. formals bind raw operands; envarg is bound to the caller’s environment.

Example

(define q (vau (x) _ x))
(q (+ 1 2))  ; ⇒ (+ 1 2)

define

operative

(define lhs rhs)

Evaluates rhs, then pattern-binds lhs in the current environment.

(defn (pts x y) (list x y))
(define answer 42)

if

operative

(if test consequent alternative)

Evaluates test; runs exactly one branch. Requires Kernel booleans #t/#f.

(if (< 1 2) 'yes 'no)  ; ⇒ yes

eval

applicative

(eval environment expression)

Evaluates expression in the given environment value.

(define e (make-environment (get-current-environment)))
(eval e '(define x 7))
(eval e 'x)  ; ⇒ 7

wrap

applicative

(wrap combiner)

Returns an applicative that evaluates arguments, then operates the underlying combiner.

unwrap

applicative

(unwrap applicative)

Extracts the underlying combiner from an applicative.

(define op (vau (x) _ x))
((unwrap (wrap op)) (+ 1 2))  ; ⇒ (+ 1 2)

load

applicative

(load filename)

Reads and evaluates a .scm file in the current environment; result is #inert.

make-encapsulation-type

applicative

(make-encapsulation-type) → (encapsulator predicate decapsulator)

Creates a unique encapsulation type (used by the promises library).

Arithmetic & comparison

Binary applicatives over CLR-boxed numbers (Obj). Mixed int/float is supported.

+

applicative

(+ a b)

(+ 2 (* 4 3))  ; ⇒ 14

-

applicative

(- a b)

*

applicative

(* a b)

/

applicative

(/ a b)

<   <=   >

applicative

(< a b) (<= a b) (> a b)

(<= 2 2)  ; ⇒ #t

eq? / eqv?

applicative

(eqv? a b)

Structural equality for lists; Object.Equals for CLR objects; identity-style for atoms/bools.

Lists & pairs

cons

applicative

(cons a b)

(cons 1 (cons 2 ()))  ; ⇒ (1 2)
(cons 1 2)            ; ⇒ (1 & 2)

car / cdr

applicative

(car pair) (cdr pair)

Vectors

vector

applicative

(vector …elems) or literal [e1 e2 …]

make-vector

applicative

(make-vector size fill)

vector-ref / vector-set!

applicative

(vector-ref v i) (vector-set! v i value)

(define v (vector 10 20 30))
(vector-set! v 0 7)
(vector-ref v 0)  ; ⇒ 7

Predicates

null? pair? zero? vector? environment?

applicative

(null? x) (pair? x) (zero? x) (vector? x) (environment? x)

(null? ())      ; ⇒ #t
(pair? '(a))    ; ⇒ #t
(zero? 0)       ; ⇒ #t
(vector? [1])   ; ⇒ #t

Environments

make-environment

applicative

(make-environment parent…)

Fresh mutable environment whose parent frames are the arguments (optional).

Continuations

call/cc

applicative

(call/cc combiner)

Passes the current full continuation to an applicative (or invokes a continuation).

(call/cc (lambda (k) (* 5 (k 4))))  ; ⇒ 4

reset

operative

(reset expression)

Installs a delimiter for shift.

shift

applicative

(shift combiner)

Captures the delimited continuation up to the enclosing reset.

(+ 1 (reset (+ 2 (shift (lambda (k) 3)))))
; ⇒ 4

.NET interop

new

operative

(new TypeName arg…)

TypeName is an atom (resolved across loaded assemblies). Remaining operands are constructor args (currently expected as values / evaluated by surrounding applicatives as usual for nested forms).

(new System.Text.StringBuilder)

.

operative

(. target MethodName arg…)

Instance or static method invoke. target is an object or type-name atom. Arguments are evaluated.

(. System.Guid NewGuid)
(. System.String Format "{0}-{1}" 1 2)

.get / .set

operative

(.get target PropertyOrField) (.set target PropertyOrField value)

For static members, target is a type-name atom. Prefer evaluating instance targets before .get when they are variables (pass an object value, not a bare name that could be mistaken for a type).

(.get System.DateTime UtcNow)
(.get (.get System.DateTime Now) Ticks)

I/O & display

print / printf / show

applicative

(print obj) (printf format arg…) (show value)

printf uses .NET String.Format placeholders ({0}, {1}, …). show writes the Kernel printed representation.

open-*-file / read / write / …

applicative

(open-input-file path) (open-output-file path) (close-input-port p) (close-output-port p) (read) (read port) (write obj) (write obj port) (read-contents path) (read-all path)

Standard library kernel.scm

quote

library

(quote x) or 'x

'(a b)  ; ⇒ (a b)

sequence / begin

library

(sequence form…) (begin form…)

sequence is the Kernel-style sequential evaluator (tail context on the last form). begin is a simpler last-value helper.

list / list* / length / map

library

(list …) (list* …) (length xs) (map f xs)

(map (lambda (x) (* x 2)) (list 1 2 3))
; ⇒ (2 4 6)

lambda / λ / ϝ

library

(lambda formals body…)   λ ≡ lambda   ϝ ≡ vau

lambda expands to a wrapped vau.

apply

library

(apply appv args [environment])

let / let* / letrec / letrec*

library

(let ((v e)…) body…) …

(let ((x 2) (y 3)) (* x y))  ; ⇒ 6
(let* ((x 3) (y x)) (+ x y)) ; ⇒ 6

caar cadr cdar cddr

library

(caar x) (cadr x) …

any? / zip / for-each

library

(any? pred xs) (zip f xss…) (for-each xs f)

get-current-environment / remote-eval / bindings→environment

library

(get-current-environment) (remote-eval expr env-expr) (bindings->environment (name value)…)

(define e (bindings->environment (msg "hi")))
(remote-eval msg e)  ; ⇒ "hi"

provide! / import! / set!

library

(provide! (sym…) body…) (import! env-expr sym…) (set! target-env formals values)

defn / compose / let/cc

library

(defn (name args…) body…) (compose f g) (let/cc k body…)

(defn (square x) (* x x))
((compose square square) 2)  ; ⇒ 16

cond / and? / or? / not?

library

(cond (test body…)…) (and? …) (or? …) (not? x)

(and? #t #t #f)  ; ⇒ #f
(or? #f #f 'ok)  ; ⇒ ok

time

library

(time expression)

Times evaluation using System.DateTime and prints elapsed milliseconds.

Promises promises.scm

lazy / force / memoize / promise?

library

(lazy expression) (force x) (memoize value) (promise? x)

lazy is an operative — it captures the expression and environment without evaluating.

(define a (lazy (+ 2 5)))
(promise? a)  ; ⇒ #t
(force a)     ; ⇒ 7

Prefer learning by doing? Return to the language guide or browse Examples/ in the repo.