Skip to content

Instantly share code, notes, and snippets.

@banterCZ
Created July 11, 2014 14:10
Show Gist options
  • Save banterCZ/7cfc45683e1b4b03a965 to your computer and use it in GitHub Desktop.
Save banterCZ/7cfc45683e1b4b03a965 to your computer and use it in GitHub Desktop.
We want to write a function that generates accumulators-- a function that takes a number n, and returns a function that takes another number i and returns n incremented by i. See the article Revenge of the Nerds http://www.paulgraham.com/icad.html This Clojure solution comes from http://rosettacode.org/wiki/Accumulator_factory#Clojure
(defn accum [n]
(let [acc (atom n)]
(fn [m] (swap! acc + m))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment