Skip to the content
Diaspar

Decision D003 · accepted; C backend proposed

A compiled language with a live REPL

A record of the language's design, as it stood on 2026-11-18: written for the people who build Diaspar, and kept as it was written. Its code is a sketch, not a program of the site, and an older record may show syntax that a later one changed. It names files of the language's source, which is not public yet.

Status: accepted (2026-11-15) for compilation and a live REPL; proposed for the C backend and the order of tiers

Decision

Diaspar is a compiled language with a live REPL, like SBCL, not an interpreted one like Python. "Compiled" and "interpreted" are properties of an implementation, not of a language: a REPL means "type a form, get a result", whatever runs inside.

Implementation tiers:

Tier What it is Where it runs
Interpreter Written in Diaspar, lives inside the compiler The REPL, macro expansion, the first bootstrap steps
Compiler to C Emits C, then cc builds a binary Building programs and the compiler itself
JIT (later) MIR or copy-and-patch Compiling each REPL form, as SBCL does

How compilation coexists with redefinition

A call to a global function goes through a cell, not a direct jump to an address. Redefining the function in the REPL changes the cell, and all already compiled code calls the new version at once. The cost is one memory load per call. Release builds keep redefinition through guarded direct calls; only a --sealed build drops the cells (D026).

user=> (defn greet [name] (str "hi " name))
user=> (defn welcome [name] (greet name))
user=> (welcome "Ann")
"hi Ann"
user=> (defn greet [name] (str "hello " name))   ; redefined in the running process
user=> (welcome "Ann")                            ; welcome was not recompiled
"hello Ann"

A global function as a value is its cell (accepted, 2026-11-17)

A global function used as a value, (map f xs), (def g f), a handler stored in a table or given to an actor, is a reference to its cell, not a copy of the function it holds at that moment. Calling the value calls the definition current at the time of the call, as a call written in the code does. So a redefinition in the REPL reaches every place the function was passed to, and a running server or actor takes the new handler at its next call.

(defn f [] :old)
(def g f)                ; g refers to f's cell
(defn f [] :new)         ; redefined
(g)                      ; => :new
(= g f)                  ; => true: one cell
  • Erlang does the same for fully qualified funs: fun mod:f/1 calls the latest loaded version, and hot code loading relies on it. In Clojure, a value f is the function at the time it was read, and programs write #'f (the var) to get what this decision makes the default; forgetting #' on a Ring handler is a known trap of Clojure's REPL workflow.
  • Equality and printing: two values of one global are equal; the value prints as the function (#<fn app.f>).
  • Errors at the call: if the redefinition dropped the arity being called, the call raises the arity error of the new definition; if the name now holds something that is not a function, the call raises NotAFunction, as a written call does.
  • Cost: none in a value; a global's cell is immortal, so passing it touches no count. A call through the value is a call through the cell, the same as an ordinary call site (D026 [11]). A --sealed build passes the function itself, which cannot be told apart, since nothing can be redefined there.
  • Local functions and fn expressions are values as before: a closure is what it captured. (fn [] (f)) also calls the current f, because its body is an ordinary call.
  • No snapshot operator for now. If a program needs the definition as it is at one moment, a function for that can be added when a use appears.

Rejected: the function at the time the value is taken (Clojure's f, and the bootstrap interpreter's behaviour until this decision): every handler table, actor and callback keeps old code after a redefinition, which defeats the live environment. A separate syntax for the cell (Clojure's #'f): two meanings where one does, and the wrong one is the default.

Why

  • SBCL, Chez, Julia, and Clojure compile every REPL form. Compilation and liveness are compatible.
  • An interpreter written in Diaspar plays four roles at once: it runs macros, gives the REPL, serves as a simulator for debugging the runtime instead of gdb, and leads to a portable bootstrap seed.
  • C instead of LLVM:
    • Ferron's bootstrap stages with LLVM took 10–30 minutes each;
    • jank and Clasp keep breaking on LLVM's unstable C++ API;
    • C text can be emitted from any language and built by any cc; musttail is in GCC 15 and Clang;
    • QBE reaches about 70% of LLVM's performance in under 8k lines of code, a fallback of the same class.
  • Compiling each REPL line through C is too slow (tens of milliseconds per cc run), so the REPL uses the interpreter first and a JIT later.

Commitment

The interpreter and the compiler give the same result on the same code. Every language test runs in both modes.

Rejected alternatives

  • Interpreter only (as in Python, Janet): too slow for a general-purpose language.
  • Compilation only, no REPL: loses the defining property of a Lisp.
  • LLVM as the main backend: a heavy dependency and slow stages; possible later as an optional backend for release builds.