Skip to content

Instantly share code, notes, and snippets.

@mfikes
Created April 20, 2015 18:57
Show Gist options
  • Save mfikes/c9842b04392a2b6f7d4e to your computer and use it in GitHub Desktop.
Save mfikes/c9842b04392a2b6f7d4e to your computer and use it in GitHub Desktop.
Nashorn volatiles in terms of atoms
$ git diff
diff --git a/src/cljs/cljs/core.cljs b/src/cljs/cljs/core.cljs
index 2794acc..4f69f06 100644
--- a/src/cljs/cljs/core.cljs
+++ b/src/cljs/cljs/core.cljs
@@ -3882,18 +3882,18 @@ reduces them without incurring seq initialization"
[iref]
(.-validator iref))
-(deftype Volatile [^:mutable state]
+(deftype Volatile [state]
IVolatile
(-vreset! [_ new-state]
- (set! state new-state))
+ (reset! state new-state))
IDeref
- (-deref [_] state))
+ (-deref [_] @state))
(defn volatile!
"Creates and returns a Volatile with an initial value of val."
[val]
- (Volatile. val))
+ (Volatile. (atom val)))
(defn volatile?
"Returns true if x is a volatile."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment