Created
July 11, 2014 14:10
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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