Skip to content

Instantly share code, notes, and snippets.

@ctran
Created April 10, 2011 16:25
Show Gist options
  • Save ctran/912488 to your computer and use it in GitHub Desktop.
Save ctran/912488 to your computer and use it in GitHub Desktop.
Y combinator.
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