Welcome! Please see the About page for a little more info on how this works.

+1 vote
in ClojureScript by

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

1 Answer

0 votes
selected by
Best answer

Pretty sure this is for historical reasons. But it's really neither here nor there, you can't really call these core protocol methods directly in general as there are lot of cases to handle. Perusing the other wrappers for protocol methods makes this quite clear.