Created
May 23, 2015 02:23
-
-
Save jimmcslim/2bca29350629e21bd799 to your computer and use it in GitHub Desktop.
Workshop Gist #1
This file contains hidden or 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 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