题目的例子等价于:
(let ((x 3)) (let ((y (+ x 2))) (let ((z (+ x y 5))) (* x z))))
于是代码如下:
(define (make-let bindings body) (cons 'let (cons bindings body)))(define (let*->nested-lets exp) (define (expand-let* bindings body) (if (null? bindings) body (list (make-let (list (car bindings)) (expand-let* (cdr bindings) body))))) (car (expand-let* (cadr exp) (cddr exp))))