Created
April 10, 2011 16:25
-
-
Save ctran/912488 to your computer and use it in GitHub Desktop.
Y combinator.
This file contains 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 Y | |
"Y combinator." | |
[f] | |
((fn [x] | |
(f (fn [y] ((x x) y)))) | |
(fn [x] | |
(f (fn [y] ((x x) y)))))) | |
(defn Y | |
"Y combinator." | |
[r] | |
(#(% %) #(r (fn [y] ((% %) y))))) | |
(defn fact [rec] (fn [n] | |
(if (zero? n) | |
1 | |
(* n (rec (dec n)))))) | |
((Y fact) 6) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment