λ 演算与 Y 组合子

· · 个人记录

猜猜这是什么。

> (define (Z f)
    ((lambda (x) (x x))
     (lambda (x)
       (f (lambda (v) ((x x) v))))))
> (define (fact f) (lambda (x) (if (< 0 x) (* x (f (- x 1))) 1)))
> ((Z fact) 3)
6

当然,你不能在 chez scheme(或其他的任何 call-by-value 的语言)中直接使用 Y-combinator。这里使用的是 Z 组合子,是 Y-combinator 的一个变体。