; Examples of implementing both the ; lazy Y fixed point combinator and ; the eager Turing fixed point combinator ; using Scheme ; ; lazy Y combinator ; (define Y (lambda (f) ((lambda (x) (f (x x))) (lambda (x) (f (x x)))))) ; the following defintion of fact fails to terminate using ; the lazy Y combinator ; ;(define fact ; (Y (lambda (f) ; (lambda (n) ; (if (zero? n) 1 (* n (f (- n 1)))))))) ; ; applicative order Y combinator (modified Turing combinator) ; (define Y (lambda (f) ((lambda (x) (f (lambda (y) ((x x) y)))) (lambda (x) (f (lambda (y) ((x x) y))))))) ; ; factorial using the applicative order Y combinator ; (define Y-fact (Y (lambda (f) (lambda (n) (if (zero? n) 1 (* n (f (- n 1)))))))) ; ; modified "Turing" combinator ; (define T (lambda (f) ((lambda (x) (f (x x))) (lambda (x) (f (lambda (y) ((x x) y))))))) ; ; factorial using the modified T combinator ; (define T-fact (T (lambda (f) (lambda (n) (if (zero? n) 1 (* n (f (- n 1)))))))) ; ; tail recursive factorial using a named let ; (define let-fact (lambda (n) (let f ((n n) (m 1)) (if (zero? n) m (f (- n 1) (* m n)))))) ; ; redefined using a letrec ; (define letrec-fact (lambda (n) ((letrec ((f (lambda (n m) (if (zero? n) m (f (- n 1) (* m n)))))) f) n 1)))