Created
January 7, 2015 21:57
-
-
Save jvanwinden/c1f5224c97ec48b7ea46 to your computer and use it in GitHub Desktop.
Common Lisp 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
(defun Y-combinator (f) | |
((lambda (h) | |
(funcall h h)) | |
(lambda (self) | |
(funcall | |
f | |
(lambda (&rest args) | |
(apply | |
(funcall self self) | |
args))))) | |
(defun factorial (n) | |
(funcall | |
(Y | |
(lambda (f) | |
(if (= 0 n) | |
1 | |
(* n (funcall f (- n 1)))))) | |
n)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment