(define fix (lambda (f) ((lambda (x) (f (lambda (y) ((x x) y)))) (lambda (x) (f (lambda (y) ((x x) y))))))) (define fac (fix (lambda (fact) (lambda (n) (if (= n 0) 1 (* (fact (- n 1)) n)))))) (fac 6) ; => 720In pure lambda form, without benefit of ‘define’ the factorial function is:
((lambda (fix) (fix (lambda (fact) (lambda (n) (if (= n 0) 1 (* (fact (- n 1)) n)))) )) (lambda (f) ((lambda (x) (f (lambda (y) ((x x) y)))) (lambda (x) (f (lambda (y) ((x x) y)))))))Note that the third line has the factorial idea and that recursion has been defined instead of postulated. I think that the Y combinator is the origin of this construct. Alas this code is obscure, if short. There are two senses of “expressive” as a language attribute:
Equivalently factorial is:
((λ (f) ((λ (x) (f (λ (y) ((x x) y)))) (λ (x) (f (λ (y) ((x x) y)))))) (λ (fact) (λ (n) (if (= n 0) 1 (* (fact (- n 1)) n)))))