Do not do this! Save yourself before this too late! Mutating a state for no reason is not something that Clojure encourages, so of course it's not as convenient as lisp would normally be.
But seriously, this is a classic example of explaining closures, and although this is not very useful in Clojure, it's nice to know the translation. You need to write something like:
(defn foo [n] (let [acc (atom n)] (fn [i] (swap! acc + i))))
amalloy
source share