Skip to content

Instantly share code, notes, and snippets.

@shinmuro
Created March 26, 2014 04:14
Show Gist options
  • Save shinmuro/9776860 to your computer and use it in GitHub Desktop.
Save shinmuro/9776860 to your computer and use it in GitHub Desktop.
(require '[clojure.core.memoize :as memo]) ; もちろんここは一度きり
(def func-a-lrufn (memo/lru (fn [some-params] (some-proc some-params))))
(defn func-a
[some-params]
(func-a-lrufn some-params))
(defmacro defn-lru
[name [& params*] threshold-val & body] ;; <- ん?
(let [private-fn (symbol (str name "-lrufn"))]
`(do
(def ~(with-meta private-fn {:private true})
(memo/lru (fn [~@params*] ~@body) :lru/threshold ~threshold-val))
(defn ~name [~@params*] (~private-fn ~@params*)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment