From a9403e26b044327b23d40869c5701ee3d5d0813e Mon Sep 17 00:00:00 2001 From: Yogthos Date: Sun, 7 Jun 2026 21:27:20 -0400 Subject: [PATCH] =?UTF-8?q?core:=20Phase=204=20=E2=80=94=20move=20vreset!/?= =?UTF-8?q?vswap!=20to=20the=20overlay=20(reusing=20ref-put!)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit vreset! sets the volatile's :val slot through the jolt.host/ref-put! primitive added in the last batch; vswap! is pure over vreset! + get. The volatile! constructor stays native (it builds the mutable box). Covered by the existing state spec. --- jolt-core/clojure/core/20-coll.clj | 7 +++++++ src/jolt/core.janet | 10 ++-------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/jolt-core/clojure/core/20-coll.clj b/jolt-core/clojure/core/20-coll.clj index 1da5612..ebcd446 100644 --- a/jolt-core/clojure/core/20-coll.clj +++ b/jolt-core/clojure/core/20-coll.clj @@ -286,3 +286,10 @@ (jolt.host/ref-put! (get a :watches) key nil) a) (defn set-validator! [a f] (jolt.host/ref-put! a :validator f) nil) + +;; Volatiles. The constructor (volatile!) stays native — it builds the mutable box — +;; but vreset! sets the box's slot through ref-put! and vswap! is pure over it + get. +(defn vreset! [vol newval] + (jolt.host/ref-put! vol :val newval) newval) +(defn vswap! [vol f & args] + (vreset! vol (apply f (get vol :val) args))) diff --git a/src/jolt/core.janet b/src/jolt/core.janet index fa6b8c2..c0b2530 100644 --- a/src/jolt/core.janet +++ b/src/jolt/core.janet @@ -2087,12 +2087,8 @@ # Volatiles — typed box so deref/volatile? can recognize them. (defn core-volatile! [v] @{:jolt/type :jolt/volatile :val v}) -# volatile? now lives in the Clojure collection tier (tagged-value predicate). -(defn core-vswap! [vol f & args] - (def new-val (apply f (vol :val) args)) - (put vol :val new-val) - new-val) -(defn core-vreset! [vol val] (put vol :val val) val) +# volatile? / vreset! / vswap! now live in the Clojure collection tier — vreset! +# over jolt.host/ref-put!, vswap! over vreset! + get. The constructor stays native. # Delays — created lazily by the `delay` macro; forced once via force/deref. (defn core-make-delay [thunk] @{:jolt/type :jolt/delay :fn thunk :realized false :val nil}) @@ -3022,8 +3018,6 @@ "implements?" core-implements? "type->str" core-type->str "volatile!" core-volatile! - "vswap!" core-vswap! - "vreset!" core-vreset! "Thread" core-Thread "ThreadLocal" core-ThreadLocal "IllegalStateException" core-IllegalStateException