You must log in or # to comment.
This has no business looking this satisfying
Goofy but aesthetically pleasing impl
This isn’t goofy, this is an extremely diffused “pattern” when you need to use non dynamic number sequences.
Dynamic programming /s
best of both world with Lisp macros :)
(defmacro gen-fib [size] (let [values (->> (iterate (fn [[a b]] [b (+ a b)]) [0 1]) (map first) (take size) (vec))] `(defn ~'fib [~'n] (~values ~'n)))) (macroexpand-1 '(gen-fib 10)) ;=> (clojure.core/defn fib [n] ([0 1 1 2 3 5 8 13 21 34] n)) (gen-fib 10) (fib 9) ;=> 34