flan/test/programs/dev-loop.flan
Joseph Ferano a4c6b996ff def re-runs its initialiser, and defvar is renamed defonce
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.
2026-09-21 07:12:04 +07:00

38 lines
1.3 KiB
Plaintext

;;;; What [flan dev] launches: a program with a loop, a function to redefine,
;;;; and a way to stop.
;;;;
;;;; It names no socket. Under [flan dev] the daemon has already decided where
;;;; it wants to talk to this program and says so in FLAN_AGENT_SOCKET — which
;;;; overrode whatever the source named anyway — so the argument was only ever
;;;; a value nothing read. This is the shape a program should be written in,
;;;; and the whole daemon block in test_dev.ml runs against it, so a delivery
;;;; landing there is the zero-argument form working end to end.
(import agent "vendor:agent")
(defonce ticks i64)
;;; A condition and something that signals it, so that a body typed in later
;;; can establish a handler and transfer past this frame — spec-conditions.md
;;; §6. It is here rather than in the evaluated form on purpose: the guard that
;;; forwards the transfer has to be one the *host* was compiled with.
(defstruct Missing [id i32])
(defn probe [] i64
(signal (Missing {.id 1}))
0)
(defn step [] i64
(set ticks (+ ticks 1))
ticks)
(defn main [] i32
(agent/start)
(print (step)) (println "")
(while (= (agent/wait 100) 0) 0)
(print (step)) (println "")
(while (= (agent/wait 100) 0) 0)
(print (step)) (println "")
(while (= (agent/wait 100) 0) 0)
(print (step)) (println "")
0)