3. REPL
The REPL reads an entry, evaluates each of its top-level forms on its own,
and prints each result as one canonical DUST form. A list keeps its brackets,
so [1 2 (+ 3 4)] prints [1 2 7]. It keeps history and highlights input as
you type. A form that spans lines continues until its brackets balance.
> (+ 1 2) compile 77.9µs · 143.1KiB arena · key 5d902e22 · 1/64 cached 3 eval 57.9µs cpu · 130.5KiB peak · +4.6KiB net · 323.5KiB live > (+ 1 2) 3 eval 17.3µs cpu · 128.5KiB peak · +2.5KiB net · 326.0KiB live
A local form defines a top-level local that later entries read:
> (local rate 3) compile 47.9µs · 129.0KiB arena · key 64c24dfd · 2/64 cached .rate eval 10.6µs cpu · 5.7KiB peak · +3.3KiB net · 580.8KiB live > [.rate (* .rate 2)] compile 81.8µs · 130.3KiB arena · key eb0abee0 · 3/64 cached [3 6] eval 8.1µs cpu · 8.4KiB peak · +5.5KiB net · 586.3KiB live
Table of Contents
3.1. Loading namespaces ↑
!load PATH [ALIAS] evaluates a file and binds each local its
export forms name under a namespace as a constant. The file's
other locals stay private. PATH is relative to the working directory and the
.dust extension is implied. The namespace is ALIAS, or else the last path
segment. Loading a namespace again replaces its bindings. A namespace whose
names match library entries, such as math/pi, is rejected with
#err <conflict name>; load it under an alias instead, as in
!load lib/math m. A line that starts
with ! is a REPL command; every other line is DUST, so :shapes/square is
a constant reference.
Given lib/shapes.dust:
(local double (fn [x] (+ .x .x)))
(local square (fn [x] (* .x .x)))
(export square double)
> !load lib/shapes shapes: square double > (shapes/square 7) 49 eval 140.8µs cpu · 116.8KiB peak · -128.6KiB net · 209.7KiB live > !load lib/shapes s s: square double > (s/double 4.5) 9.0 eval 17.7µs cpu · 130.5KiB peak · +5.8KiB net · 228.0KiB live
What a library path names is up to each runtime. The REPL reads files; Stardust resolves the same paths within its database.
!reset drops every top-level local, loaded namespace, and compiled entry
and starts a fresh runtime with only the core libraries:
> !load lib/shapes
shapes: square double
> !reset
reset: locals, namespaces, and compiled programs cleared
> (shapes/square 7)
#err {<expected function>
message "expected a function value"} eval 28.3µs cpu · 144.4KiB peak · -136.6KiB net · 539.7KiB live