Skip to content

Instantly share code, notes, and snippets.

@alandipert alandipert/fib.clj
Created Jan 3, 2010

What would you like to do?
;; Y combinator and fib in clojure
;; see also:
;; p72
(defn Y [f]
((fn [g]
(f (g g)))
(fn [g]
(fn [x]
((f (g g)) x)))))
(defn fib [k]
((Y (fn [f]
(fn [n]
(= n 0) 0
(= n 1) 1
:else (+ (f (- n 1)) (f (- n 2))))))) k))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.