Exercise 4.6
let 式を等価の lambda 式に変形する問題。
(define (let->combination exp) (let ((body (let-body exp)) (bind (let-bind exp))) (cons (cons 'lambda (cons (let-parameters bind) body)) (let-arguments bind)))) (define (let-parameters exp) (map car exp)) (define (let-arguments exp) (map cadr exp)) (define (let-bind exp) (cadr exp)) (define (let-body exp) (cddr exp))
とやってみた。 Gauche 上で動かしてみて、
gosh> (let->combination '(let ((a 1)(b 2)) (print "abc") (+ a b))) ((lambda (a b) (print "abc") (+ a b)) 1 2) gosh> (eval (let->combination '(let ((a 1)(b 2)) (print "abc") (+ a b))) '()) abc 3
と出るので、おそらく正しい。