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