Skip to content
Konjure / spatial intelligence

Modules

Link explicit sources and expose a deliberate public surface.

A module is source that the host supplies under a name. import makes that name available; export chooses declarations that other modules may use. The language never reads local files, fetches URLs, or installs packages while linking, so the program’s source inputs are explicit and diagnostics can retain them.

Import one public function

Run this fixture. Its main.kj imports counters; select counters.kj in Files to inspect the supplied module. Its output is 2 followed by 5.

Tick 0 · 0.00 sThis device
main.kj⌘ / Ctrl + Enter
Loading the language runtime…
Output 0
No output.

import counters; does not copy names into the entry module’s unqualified namespace: call an exported function as counters.name(...). Types, traits, and top-level bindings can also be exported. Imported constructors and types remain qualified, such as shapes.Ball { radius: 0.3 }. Put mutable imported state behind an exported function so its defining module owns the update.

The entry module is main; builtin is the automatic standard module. Both names are reserved. An import of an absent source or access to a private name produces a diagnostic.

Dependencies initialize before their importers, and a module imported more than once is loaded once. Top-level statements initialize runtime state; functions and types declare the names available to that state. Systems in imported modules also run before importer systems. Import cycles are rejected.

Edit exercise

In counters.kj, change self.value = self.value + by to self.value = self.value + by + 1, compile, and expect the main fixture’s second output to change from 5 to 6. Remove export new_counter; and compile again: the main module should receive a diagnostic for accessing a non-public name.

Module names are part of source identity. Package discovery, version resolution, filesystem search paths, aliases, selective imports, and live module replacement are not implemented. The language reference defines linking and initialization; see language design for future directions.

When embedding from Rust, pass the entry source and named module map to compile. The SDK development guide covers the native iteration workflow.