Skip to content

Instantly share code, notes, and snippets.

@jcoglan
Created January 14, 2009 23:28
Show Gist options
  • Save jcoglan/47157 to your computer and use it in GitHub Desktop.
Save jcoglan/47157 to your computer and use it in GitHub Desktop.
; Turns out if your Scheme is lazy, you can do this:
(define (Y f)
(f (Y f)))
; I'm not kidding, watch:
(define fact (Y (lambda (rec)
(lambda (x)
(if (= x 0)
1
(* x
(rec (- x 1))))))))
(display (fact 6))
; => 720
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment