In TSPL 3.2 we find:
(letrec ((even?
(lambda (x)
(or (= x 0)
(odd? (- x 1)))))
(odd?
(lambda (x)
(and (not (= x 0))
(even? (- x 1))))))
;; (list (even? 20) (odd? 20))) => (#t #f)
but the same program, if use let instead of letrec, still can run in ChezScheme:
(let ((even?
(lambda (x)
(or (= x 0)
(odd? (- x 1)))))
(odd?
(lambda (x)
(and (not (= x 0))
(even? (- x 1))))))
Is it a Chez's bug? TSPL can't be wrong. Thanks!
The built in scheme functions
even?andodd?are what are being called in the bodies of the lambdas in theletversion. Use different names and you'll get an error:will fail. Change it to
letrecand it'll work because your function names will then be in scope in the lambda bodies.