Created
January 14, 2009 23:28
-
-
Save jcoglan/47157 to your computer and use it in GitHub Desktop.
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
; 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