Skip to content

Instantly share code, notes, and snippets.

@jvanwinden
Created January 7, 2015 21:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jvanwinden/c1f5224c97ec48b7ea46 to your computer and use it in GitHub Desktop.
Save jvanwinden/c1f5224c97ec48b7ea46 to your computer and use it in GitHub Desktop.
Common Lisp Y-combinator
(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