The trio the author decided on 2026-09-20 is now all built: def is CL's defparameter — its initialiser runs on every daemon re-run, unguarded, so an edited initialiser repaints the same storage on C-c C-c plus re-run — defonce (Clojure's name for CL's defvar, per the author) initialises once behind the .init~once. flag, and defconst stays the image. One parse arm reads both forms; the difference is Ast.reinit, carried to Tast.global's grerun. Emit.startup_plan gives a def no guard flag, and Check.check_global lifts every def initialiser — zero and literal included — into global/<n>, so the host's startup reaches it through the function cell and a re-evaluated def swaps it (Session's def_inits; Emit.redefinition declares the cell for a non-sibling target). The old defvar spelling is refused with the rename and both compiling spellings, and every program, test, doc and editor list is swept — except sand.flan, the author's live WIP, whose seven defvar lines are flagged in FIX.org and keep its three dependent tests red on this branch.
40 lines
1.4 KiB
Plaintext
40 lines
1.4 KiB
Plaintext
;;;; A program that stops with state worth looking at *outside* the frame.
|
|
;;;;
|
|
;;;; dev-locals.flan is about what one frame holds. This is about what the
|
|
;;;; whole stopped stack is reading, which in this language is most of the
|
|
;;;; program: a game keeps its state in top-level defonces, and sand.flan holds
|
|
;;;; its entire grid that way.
|
|
;;;;
|
|
;;;; The globals are declared in an order the answer must *not* come back in.
|
|
;;;; [label] is written first and is touched only by [main], the outer frame,
|
|
;;;; so ordering by the innermost frame that touches it has to put it last;
|
|
;;;; [grid] and [pressure] are both innermost-touched and must keep the order
|
|
;;;; they are declared in. [untouched] is read by no frame on the stack and
|
|
;;;; must not appear at all — that is the whole claim of scoping the section to
|
|
;;;; the stack rather than listing everything the program has.
|
|
(import agent "vendor:agent")
|
|
|
|
(defstruct Boom [why i32])
|
|
|
|
(defonce label string)
|
|
(defonce grid [4 i32])
|
|
(defonce pressure i64)
|
|
(defonce untouched i64 99)
|
|
|
|
;; The inner frame. It writes two globals and then errors with nothing
|
|
;; handling the condition, so the program stops here with [main] under it.
|
|
(defn inner [] i64
|
|
(set pressure 12)
|
|
(set (at grid 0) 7)
|
|
(error (Boom {.why 3}))
|
|
0)
|
|
|
|
(defn main [] i32
|
|
(agent/start "/tmp/flan-dev-globals-fallback.sock")
|
|
(set label "running")
|
|
(set (at grid 1) 5)
|
|
(print (inner)) (println "")
|
|
(dotimes [i 4000]
|
|
(agent/wait 5))
|
|
0)
|