Operator reference
Primitive operatives and applicatives ship with the runtime; the standard library
(kernel.ikr / promises.ikr) 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 expression environment)
Evaluates expression in the given environment value.
(define e (make-environment (get-current-environment)))
(eval '(define x 7) e)
(eval 'x e) ; ⇒ 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 .ikr 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) ; ⇒ #teq? / 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)))) ; ⇒ 4reset
operative(reset expression)
Installs an untagged delimiter for multi-shot shift.
shift
applicative(shift combiner) (shift prompt-tag combiner)
Captures the delimited continuation up to the enclosing reset,
or up to the nearest matching tagged prompt when a tag is supplied.
(+ 1 (reset (+ 2 (shift (lambda (k) 3)))))
; ⇒ 4
Effects & async
Tagged handlers use unforgeable prompt tags. Resumptions from perform are
one-shot; async primitives require the unrestricted capability profile.
make-prompt-tag
applicative(make-prompt-tag)
Creates a unique, unforgeable prompt tag value.
prompt
operative(prompt tag-expr handler-expr body)
Evaluates the tag and handler, then runs body under a deep handler for that tag.
The handler receives (value resumption). Returning without resume
aborts the captured computation and invalidates the resumption.
(define request (make-prompt-tag))
(prompt request
(lambda (value k) (resume k (+ value 1)))
(+ 1 (perform request 40)))
; ⇒ 42
perform
applicative(perform prompt-tag value)
Invokes the nearest matching tagged handler with value and a one-shot resumption.
Errors if no matching handler is installed.
resume
applicative(resume resumption value)
Continues a captured computation with value. Reinstalls the same tagged handler.
Resuming twice is an error.
task-delay
applicative(task-delay milliseconds value)
Returns a CLR Task that completes with value after the delay.
Requires the HostAsync capability (unrestricted profile).
await-task
applicative(await-task task)
Suspends evaluation until the CLR task completes, then resumes on the trampoline
(never on the callback thread). Requires HostAsync.
(await-task (task-delay 25 "ready"))
; ⇒ "ready"
Contracts
Contracts are optional combiner metadata. User contracts assert shapes at call boundaries; only compiler-certified pure primitives may be partially evaluated.
contract
operative(contract name mode (operand-shape…) result-shape effect inlineable?)
Attaches a contract to the named binding.
mode is operative (raw operands) or applicative (evaluated args).
effect is pure or effectful.
Shapes: any, number, integer, string,
boolean, atom, list, prompt-tag,
resumption.
(define double (lambda (x) (+ x x)))
(contract double applicative (number) number pure #t)
contract-of
applicative(contract-of value)
Returns #f when unbound, otherwise a list describing mode, operand shapes,
result shape, effect, inlineability, and trust (asserted / certified).
.NET interop
Raw reflection (new, ., .get, .set,
clr-open, …) requires host CLR capabilities. Under --profile safe,
use generated wrappers such as Console.write-line, String.concat,
and Math.sqrt from the reviewed manifest instead.
Type names resolve as: exact full name, then clr-alias, then each
clr-open prefix. Ambiguous short names error. Unbound Clojure-style heads
desugar to these primitives: (Type/Method …), (Type. …),
(.method instance …), (.-field instance).
clr-open
operative(clr-open Namespace…)
Appends namespace prefixes to the current environment’s CLR search path. Child environments and operative closures inherit the opens.
(clr-open System System.IO)
(Guid/NewGuid)
(Path/GetExtension "a.ikr")
clr-alias
operative(clr-alias ShortName FullTypeName)
Binds a short name to a full CLR type name in the current environment.
(clr-alias SB System.Text.StringBuilder)
(new SB)
clr-type
operative(clr-type TypeName)
Resolves a type (using opens/aliases) and returns it as a first-class
<type …> value usable with ., new, and .get.
clr-opens
applicative(clr-opens)
Returns the current environment’s opened namespace list.
new
operative(new TypeName arg…) (new type-value arg…)
TypeName is an atom resolved across loaded assemblies (and opens/aliases). A clr-type value is also accepted. Sugar: (TypeName. arg…).
(new System.Text.StringBuilder)
(StringBuilder.).
operative(. target MethodName arg…)
Instance or static method invoke. target is an object, type-name atom, or type value. Arguments are evaluated. Sugar: (Type/Method …), (.Method instance …).
(. System.Guid NewGuid)
(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 or type value. Sugar: (.-Field instance).
(.get System.DateTime UtcNow)
(.-Length "abc")
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.ikr
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.ikr
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.