Skip to content
Konjure / spatial intelligence

Language reference

Syntax, types and execution rules for the implemented language.

Use the language guide for runnable lessons and the standard library for generated builtin signatures.

Source and declarations

Programs use .kj source. Braces delimit blocks; simple statements and type fields end in semicolons. Generic arguments use square brackets.

ConstructForm
Functionfunc name(x: T) -> T { ret x; }
Bindinglet name: T = value; or let mut name: T = value;
Typetype Name { field: T; func read() -> T { ... } }
Type constructionName { field: value }
Enumenum State { Idle, Moving(f32) }
Enum constructionState.Moving(1:f32)
Traittrait Name { func method() -> Unit; }
Implementationimpl Trait for Type { ... }
Matchmatch value { State.Idle => a, State.Moving(speed) => b }
Systemsystem Name of T { ... }

class is retired; use type. Identifiers begin with an ASCII letter or underscore, followed by ASCII letters, digits, or underscores. // starts a line comment. Strings are UTF-8 text and support \n, \r, \t, \", and \\ escapes. and and or require Bool operands and short-circuit; && and || are rejected with a diagnostic naming their replacement.

Values and checked data

Bool, Str, Bin, Unit, Entity, fixed numeric dtypes, List[T], and Tensor[T] are built in. Number aliases f64. Types are nominal; imported type identity includes its module. Res[T, E] and Opt[T] are algebraic values with bare constructors Ok, Err, Some, and None.

Every match must be exhaustive and no arm may be unreachable. ? propagates only from a Res or Opt expression to a compatible enclosing Res or Opt return. Checked numeric and tensor arithmetic produces Res[..., DataError]. The top-level initializer implicitly returns Res[Unit, DataError].

Str.len, Str.utf8, Str.get; Bin.len, Bin.decode, Bin.get; List.len, List.append, List.get; and the tensor methods are receiver-owned. See Numbers, text and bytes and Tensors and media for their result types. The former global data helpers are unavailable. print, range, and the checked tensor[T](values, shape) constructor remain top-level operations.

Systems and transactions

Each entity holds at most one component of each concrete type. system Name of T selects matching components and supplies typed mutable bindings. Lifecycle callbacks return Unit or Res[Unit, DataError]. An Err returned from a callback rejects and rolls back the host transaction; an Err stored inside an ordinary value remains ordinary data.

Execution checks every body before running it. A transaction failure rolls back component edits, globals, logs, entity IDs, and lifecycle membership. Limits bound recursion, evaluation, allocations, tensor shape, and retained storage. The browser displays Rust-produced values, diagnostics, source metadata, and read-only inspection summaries; it does not execute arbitrary host code.