Created
September 20, 2018 10:54
-
-
Save jiamo/8499bb69d791d524d487755ee392323c to your computer and use it in GitHub Desktop.
Ycombinator2
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
#lang racket | |
;(Y f) = fixpoint-of-f | |
;(f fixpoint-of-f) = fixpoint-of-f | |
;(Y f) = fixpoint-of-f = (f fixpoint-of-f) | |
;(Y f) = (f (Y f)) | |
(define (Y f) (f (Y f))) | |
(define Y-lambda | |
(lambda (f) | |
(f (Y-lambda f)))) | |
;; reverse use lambda to add a arg | |
(define Y-Strict | |
(lambda (f) | |
(f (lambda (x) ((Y-Strict f) x))))) | |
(define almost-factorial-half | |
(lambda (f) | |
(lambda (n) | |
(if (= n 0) | |
1 | |
(* n (f (- n 1))))))) | |
; why this can't work | |
(define identity (lambda (x) x)) | |
(define factorial0 (almost-factorial-half identity)) | |
(define factorial1 | |
(almost-factorial-half factorial0)) | |
(define factorial2 (almost-factorial-half factorial1)) | |
(define factorial3 (almost-factorial-half factorial2)) | |
(define factorial-strict (Y-Strict almost-factorial-half)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment