From 0a8dc1d82b6344bbedfc34075b5dbdb8cce6de20 Mon Sep 17 00:00:00 2001 From: Joseph Ferano Date: Mon, 21 Sep 2026 07:34:43 +0700 Subject: [PATCH] sand.flan takes the def/defonce split The colours were the report: edited, re-evaluated, unchanged, because defvar had said init-once and meant it. They are a def now, and so is gravity, which is a number to turn while the sand falls, and game-data, which is a file to edit and see re-read. The grid, the velocity field and the arena stay defonce: they are what the running game is, and a re-run that emptied them would be a restart wearing a re-run's name. current-color is the same argument about a smaller thing -- a brush you picked is a brush you keep. --- sand.flan | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/sand.flan b/sand.flan index 6afc3b6..3df4e51 100644 --- a/sand.flan +++ b/sand.flan @@ -12,8 +12,8 @@ (defn dyn->f64 [v f64] f64 v) (defn dyn->u32 [v i64] u32 (u32 v)) -(defvar gravity dyn 0.05) -(defvar colors dyn +(def gravity dyn 0.05) +(def colors dyn (let [v (vec-new dyn)] (push v 0xFFF00FFF) (push v 0x3B6E8CFF) @@ -21,9 +21,9 @@ (push v 0xCC6B1FFF) v)) -(defvar grid [rows [cols u32]]) -(defvar velocity [rows [cols f32]]) -(defvar current-color dyn 0) +(defonce grid [rows [cols u32]]) +(defonce velocity [rows [cols f32]]) +(defonce current-color dyn 0) (defn clear-grid [] () (set grid (zeroed)) @@ -112,8 +112,8 @@ (rl/get-color c)))))) (rl/draw-fps 20 20)) -(defvar frame Allocator (arena-new 262144)) -(defvar game-data dyn +(defonce frame Allocator (arena-new 262144)) +(def game-data dyn (handler-case (edn/read-file "game-data.edn") [(FileError [c] nil)]))