Created
April 17, 2019 10:35
-
-
Save jvkersch/27d92e8f329e1a4db81c9dd448a6b765 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| ;; Derivation of the Y combinator following Jim Weirich's approach. | |
| (define fact-improver | |
| (lambda (partial) | |
| (lambda (n) (if (= n 0) 1 (* n (partial (- n 1))))))) | |
| (define err | |
| (lambda () (error "Should not be called"))) | |
| (define fx-naive | |
| (fact-improver (fact-improver (fact-improver (fact-improver err))))) | |
| (display (fx-naive 3)) | |
| (newline) | |
| (define Y | |
| (lambda (f) | |
| ((lambda (x) | |
| (x x)) | |
| (lambda (x) | |
| (f | |
| (lambda (n) ((x x) n))))))) | |
| (define f (lambda (code) | |
| (lambda (n) (if (= n 0) 1 (* n (code (- n 1))))))) | |
| (define fx (Y f)) | |
| (display (fx 15)) | |
| (newline) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment