Skip to content

Instantly share code, notes, and snippets.

@nitin-motiani
Created April 13, 2012 19:56
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nitin-motiani/2379663 to your computer and use it in GitHub Desktop.
Save nitin-motiani/2379663 to your computer and use it in GitHub Desktop.
Y combinator in common lisp
(setf Y (lambda (g)
(funcall (lambda (f) (lambda (n) (funcall (funcall g (funcall f f)) n)))
(lambda (f) (lambda (n) (funcall (funcall g (funcall f f) n)))))))
(setf factorial (funcall Y
(lambda (f)
(lambda (n)
(if (< n 2) n
(* n (funcall f (- n 1))))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment