Skip to content

Instantly share code, notes, and snippets.

@jimmcslim
Created May 23, 2015 02:23
Show Gist options
  • Save jimmcslim/2bca29350629e21bd799 to your computer and use it in GitHub Desktop.
Save jimmcslim/2bca29350629e21bd799 to your computer and use it in GitHub Desktop.
Workshop Gist #1
(defn my-test [x]
(.log js/console "I have run for " x)
(+ x 10)
)
(defn my-memoize [x]
(fn [a]
(let [my-memoize-atom (atom {})]
(let [my-atom @!my-memoize-atom]
(if (contains? my-atom a)
(my-atom a)
(let [result (x a)]
(swap! !my-memoize-atom assoc a result)
result))))))
(let [my-test-memoize (my-memoize my-test)]
(p (my-test-memoize 20))
(p (my-test-memoize 20))
(p (my-test-memoize 30))
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment