04 Namespace files
A saved namespace is a source file identified by a path, such as
arrakis/spice. Keep related helpers, queries and other definitions together.
Use import to declare dependencies and
export to select the public names.
For example, save the spice and shipping sources from the language reference.
The configuration file arrakis.dust names the database:
{plugins {stdlib true database {path "arrakis.db"}}}
stardust namespace save arrakis/spice spice.dust --config arrakis.dust --expected-revision 0
stardust namespace save arrakis/shipping shipping.dust --config arrakis.dust --expected-revision 0
stardust namespace list arrakis --config arrakis.dust
stardust namespace read arrakis/spice --config arrakis.dust
stardust eval run.dust --config arrakis.dust
The run.dust file imports shipping and calls its function:
The result is 900.0. Paths are case-sensitive, slash-separated names. List
prefixes match complete path segments: arrakis includes arrakis/spice,
while arra does not. Reading prints the authored forms without synthetic
outer list brackets, preserving comments and function documentation.
4.1. Atomic updates
Use apply when multiple files must change together. The file contains one
ordinary DUST data map; it is not evaluated:
{changes [ {path "arrakis/spice" expected-revision 0 forms [(def reserve-percentage 10) (defn usable-spice [harvest] (/ (* harvest (- 100 reserve-percentage)) 100)) (export usable-spice)]} {path "arrakis/shipping" expected-revision 0 forms [(import <arrakis/spice>) (defn shipment [harvest] (spice/usable-spice harvest)) (export shipment)]}]}
{changes [{expected-revision 0 forms [(def reserve-percentage 10) (defn usable-spice [harvest] (/ (* harvest (- 100 reserve-percentage)) 100)) (export usable-spice)] path "arrakis/spice"} {expected-revision 0 forms [(import <arrakis/spice>) (defn shipment [harvest] (spice/usable-spice harvest)) (export shipment)] path "arrakis/shipping"}]}
changes [{expected-revision 0 forms [#invoke [def #local reserve-percentage 10] #invoke [defn #local usable-spice [#local harvest] #invoke [/ #invoke [* #local harvest #invoke [- 100 #local reserve-percentage]] 100]] #invoke [export #local usable-spice]] path arrakis/spice} {expected-revision 0 forms [#invoke [import <arrakis/spice>] #invoke [defn #local shipment [#local harvest] #invoke [spice/usable-spice #local harvest]] #invoke [export #local shipment]] path arrakis/shipping}]
stardust namespace apply install.dust --config arrakis.dust
Use a fresh database for this installation example. expected-revision 0
requires that the path does not yet exist. To replace an existing namespace,
omit expected-revision or supply its current revision from list. A stale
revision reports conflict and publishes nothing.
Change the reserve to 15 and rename usable-spice to shippable-spice in
both namespaces together:
{changes [ {path "arrakis/spice" forms [(def reserve-percentage 15) (defn shippable-spice [harvest] (/ (* harvest (- 100 reserve-percentage)) 100)) (export shippable-spice)]} {path "arrakis/shipping" forms [(import <arrakis/spice>) (defn shipment [harvest] (spice/shippable-spice harvest)) (export shipment)]}]}
{changes [{forms [(def reserve-percentage 15) (defn shippable-spice [harvest] (/ (* harvest (- 100 reserve-percentage)) 100)) (export shippable-spice)] path "arrakis/spice"} {forms [(import <arrakis/spice>) (defn shipment [harvest] (spice/shippable-spice harvest)) (export shipment)] path "arrakis/shipping"}]}
changes [{forms [#invoke [def #local reserve-percentage 15] #invoke [defn #local shippable-spice [#local harvest] #invoke [/ #invoke [* #local harvest #invoke [- 100 #local reserve-percentage]] 100]] #invoke [export #local shippable-spice]] path arrakis/spice} {forms [#invoke [import <arrakis/spice>] #invoke [defn #local shipment [#local harvest] #invoke [spice/shippable-spice #local harvest]] #invoke [export #local shipment]] path arrakis/shipping}]
stardust namespace apply update.dust --config arrakis.dust
stardust eval run.dust --config arrakis.dust
The result is now 850.0. Existing loaded aliases and retained exported
function references see this valid version on their next invocation.
Every batch checks its imports, exports, initializers and affected saved
dependents together. Removing shippable-spice while shipping still requires it
fails the batch. Correct the source or change shipping in that same batch,
then retry. The previous valid version remains available after a rejected save.
An unchanged source is a successful no-op and retains its revision. An empty
changes [] batch succeeds with tx null and no namespace entries.
Delete with the revision reported by list:
stardust namespace delete arrakis/shipping --expected-revision 12 --config arrakis.dust
Replace 12 with the actual revision. A dependent namespace must also be
updated or deleted in the same apply batch before its dependency can be
deleted.
4.2. Historical reads and sessions
read and list accept --as-of TX-OR-UTC:
stardust namespace read arrakis/spice --as-of 12 --config arrakis.dust
stardust namespace list arrakis --as-of 2026-11-08T12:00:00Z --config arrakis.dust
These bounds select application transactions. A UTC timestamp selects the latest transaction at or before that instant. A bound before the first save sees no namespace; a future bound selects the current head.
Clients can use the same operations through the database request interface:
| Method | Parameters | Result |
|---|---|---|
namespaces/read |
path, optional as-of and saved |
path, entity link, revision, source forms list, exported names as tags, and with saved true the saved time |
namespaces/list |
Optional segment prefix, as-of and saved |
Ordered list of path, entity, revision, exports, and with saved true the saved time |
namespaces/save |
changes list |
tx or null and ordered namespaces entries |
namespaces/load |
session, path, alias, optional as-of or forms; or session and sources |
Path, alias, revision and exports; with sources, {namespaces [{path exports}]} |
namespaces/check |
changes list, optional initialize, analysis and as-of |
valid, diagnostics and, with analysis true, analysis |
Each save entry contains its path, entity link, revision and deleted boolean.
Source forms are data, including quoted expressions, comments and function
definitions. Saving a definition does not invoke it. A change with forms may
give its comments as a comments map instead, from the JSON Pointer of each
value to its text, such as {"/0" "Keep spice."}. A pointer counts the source
forms from /0, map members by key and tagged payloads by tag name, as in
/0/2/#quote/1. A pointer that names no value reports invalid_comment with
its pointer; forms that also carry comments report invalid_source.
A namespace stores its comments apart from its source, so a save that changes
only comments is a new revision, and a save that changes neither publishes
nothing. Separate requests in a
submission batch are separate operations; put every coordinated change in
one namespaces/save request.
Source-file and notation clients send written (fn ...) expressions. The
distinct native function-definition kind is preserved by stored source and
owned database requests/results, but notation encoders currently reject that
kind. They do not serialize running functions or captured environments, and
do not silently change a native definition into a different kind.
namespaces/check validates changes as namespaces/save does, but saves
nothing. It examines the changed namespaces against the other saved
namespaces. A removed export that a saved namespace still imports is a
diagnostic of that namespace. The request reports each form that does not
compile and each unavailable name as {code message path name dependency
position}. A failure that stops validation, for example an import cycle, is
the last diagnostic. An old expected-revision is a conflict diagnostic.
Initializers run only with initialize true. With analysis true, the result
also has the declarations, imports, references and exports of each
changed namespace. Each item has its form-index, source-index and span.
An editor uses this request to examine a buffer while the user types.
{method "namespaces/check" params {changes [{path "dune/new" forms [(defn a [] missing) (export a)]}]}}
; result {valid false diagnostics [{code "name_unbound" path "dune/new" name "missing" message "missing" position {form-index 0 source-index 5}}]}
namespaces/load with a forms list loads unsaved source as the namespace
path, in that session only. It saves nothing. The source replaces the saved
source for the namespace and for each namespace that imports it. This
continues until the session loads the namespace again or resets. The
revision of the result is null. If the source does not compile, the load
reports the error and keeps the source that the session loaded before. An
editor uses this to try a buffer before it saves the buffer.
namespaces/load with sources loads several unsaved namespaces together,
without an alias. sources is a list of {path forms} entries. Each entry
with forms loads that source as the namespace path, as forms does. An
entry without forms removes the unsaved source of path, and the saved one,
if any, applies again. One refresh applies all entries, so the entries can
import each other in any order. When the refresh fails, the session keeps its
sources. This request needs no storage when no source imports a saved
namespace. The CLI and the nREPL server use it to load the files that an
import names (Files):
{method "namespaces/load" params {session 1 sources [{path "home/ada/app/lib/shapes" forms [(defn square [x] (* x x)) (export square)]}]}}
; result {namespaces [{exports <square> path "home/ada/app/lib/shapes"}]}
saved true in namespaces/read and namespaces/list adds saved, the time
of the transaction that saved the namespace, as a #utc value. A namespace
without a recorded time has no saved member.
eval with a namespace path evaluates code in the scope of that
namespace, as code inside the namespace. The private definitions and import
aliases of the namespace are visible. The locals and aliases of the session
are not visible. The namespace is the forms that the session loaded, if
any. Otherwise, it is the saved source. Each request runs the top-level forms
of the namespace again in a new scope, without host effects, as a load does.
Definitions that the code makes stay in the scope of that request.
{method "namespaces/save" params {changes [{path "dune/houses" forms [(def secret 7) (defn shown [] (* secret 2)) (export shown)]}]}}
{method "eval" params {code [secret (shown)] forms true namespace "dune/houses"}}
; result [7 14]
sessions/open may select an as-of transaction Integer or native UTC value.
namespaces/load can select it for an otherwise live session. The selected
context covers all code, transitive imports and database queries, and remains
fixed as later commits arrive. The session reads one database snapshot until
it closes or resets, so no later write or history removal changes what it
reads. While it is open, the database cannot reuse the pages of that snapshot,
and the file can grow. A conflicting nested query or request reports
<snapshot mismatch>. Historical contexts cannot save or delete namespaces.
sessions/reset clears the context, loaded aliases and locals. A missing
historical definition never falls back to the current one.
A failed request's result is an #err value with a code, a message and
the diagnostic's members when available: the path, position, referenced
export or import cycle (Errors and positions). If a storage failure reports
outcome "unknown", reopen the database and read the revisions before
deciding whether to retry.
4.3. Errors and positions
Every failure a request reports is one value: the result is #err of a
map, whatever failed. code is the failure's code as a set of words, such as
<unknown method>, <invalid params>, <cancelled>, <resource limit>,
<invalid program> or <mismatch type>; message is its text, when it has
one; position says where the failing form is, only when that is known. A
namespace diagnostic adds its path and name; an unsupported ABI adds
supported [1]. Inside DUST an error is #err {<tags> message …}; a
published response moves the tags into code, so (count 3) evaluates to
#err {<mismatch type> message "…"} and arrives as
#err {code <mismatch type> message "…" position {…}}. Every #err in a
result takes this form; only the value eval returns, or each value of a
forms true list, carries a position. Publishing never replaces what the
program wrote: a payload that is no map, or that itself names code,
position or value, is kept whole under value, so #err 42 arrives as
#err {code {} value 42}. The position's members are:
| Member | Meaning |
|---|---|
request |
The UUID of the request whose params.code holds the form |
path, revision |
The stored namespace whose source holds the form |
form-index |
The namespace's top-level form that holds it, counted from 0 |
source-index |
The form's cell: an index into its request Document or the namespace's forms list, the list itself being 0 |
span |
[start end], the form's byte range in the text the request was decoded from |
A request decoded with spans true has spans; one decoded without them, or
built from values, has source-index alone. Byte offsets count UTF-8 bytes.
Hosts that need a line and column compute them from their own copy of the
text.
For example, a request can contain a failing call:
{message-id #uuid "00000000-0000-4000-8000-000000000001"
method "eval"
params {code (count 3)}}
Its response contains this result:
#err {code <mismatch type>
message "count requires a list, map, string, bytes, or null"
position {request #uuid "00000000-0000-4000-8000-000000000001"
source-index 8}}
A function defined by an earlier request of the session raises its error in
that request: the position names the earlier request's UUID and its cell, so
source-index and span are read against that request. A form a macro
received keeps the position the user wrote it at; a form the macro made is
positioned at the macro call.
With forms true, each failing form's value carries its own position.
A function of a loaded namespace raises its error in the namespace's stored
source: the position names its path and revision, the form-index and the
source-index among its forms, as namespaces/read returns them, and no
span, since the store keeps forms rather than text. The
conformance/abi/positions/imported-function case shows a batch that saves,
loads and calls one. A diagnostic of namespaces/save or namespaces/load
has its path beside the code and its form-index, source-index and span
under position.
Nothing is fabricated. A cancellation, #err {code <cancelled>}, an
exhausted memory or CPU limit, an error in a function a document carried as
data, and a lookup of an unbound name have no position. Each session keeps
the positions of the sources it compiled, up to 65,536 sources and 4 MiB of
spans, within its memory limit; past those, later sources have cell indices
without spans, or no position.
Each database keeps up to 65,536 request identities for source positions in a fixed table. A collision removes the older identity. Returned Documents do not change. User errors do not expose LuaJIT or generated code messages.