This commit is contained in:
Adam Jeniski 2023-12-18 22:23:11 -05:00
parent 0c295d3f85
commit 632dcade55

View File

@ -52,15 +52,15 @@
`(let [dp# (atom {}) `(let [dp# (atom {})
f# (fn ~name ~arglist f# (fn ~name ~arglist
(or (@dp# [~@arglist]) (or (@dp# [~@arglist])
(let [res# ~@body] (let [res# (do ~@body)]
(swap! dp# assoc [~@arglist] res#) (swap! dp# assoc [~@arglist] res#)
res#)))] res#)))]
f#)) f#))
(defmacro defn-m (defmacro defn-m
"like defn but for a memoized fn, see ajet.core/fn-m" "like defn but for a memoized fn, see ajet.core/fn-m"
[name & args] [name arglist & body]
`(def ~name (fn-m ~name ~@args))) `(def ~name (fn-m ~name ~arglist ~@body)))
(defmacro log [& body] (defmacro log [& body]
(let [exprs# (map (fn [e#] (let [exprs# (map (fn [e#]
@ -115,7 +115,6 @@
distinct distinct
count) count)
(apply-each #(* % 2) #(+ % 5) 5 10) (apply-each #(* % 2) #(+ % 5) 5 10)
(apply-each-v #(* % 2) #(+ % 5) [5 10]) (apply-each-v #(* % 2) #(+ % 5) [5 10])
@ -130,4 +129,7 @@
;; 2000+ digit number generated in <16ms (leveraging polymorphism and big-int) ;; 2000+ digit number generated in <16ms (leveraging polymorphism and big-int)
;; using a seemingly naive O(n!) implementation (leveraging defn-m, autocaching) ;; using a seemingly naive O(n!) implementation (leveraging defn-m, autocaching)
(time (fib 10000N))) (time (fib 10000N))
;
)