Why does an atom not implemented the "ISwap" protocol?
It's the swap!
implementation:
(defn swap!
([a f]
(if (instance? Atom a)
(reset! a (f (.-state a)))
(-swap! a f))))
It's not about optimization because GCC does not inline the swap!
call.
;; clj -m cljs.main --optimizations advanced -co '{:pseudo-names true}' -c example.core
(let [a (atom 0)]
(swap! a inc)
(js/console.log @a))
var $a_528$$ = new $cljs$core$Atom$$;
$cljs$core$swap_BANG_$$.$cljs$core$IFn$_invoke$arity$2$($a_528$$, function($x$jscomp$125$$) {
return $x$jscomp$125$$ + 1
});
console.log($cljs$core$_deref$$($a_528$$));