2008-12-01から1ヶ月間の記事一覧

Exercise 4.9

while の展開を行う処理を考えてみる。 束縛変数のない名前付き let でループさせれば等価になるはずなので、 (define (while-predicate exp) (cadr exp)) (define (while-body exp) (cddr exp)) (define (while->let exp) (let->combination (make-named-le…

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…

Exercise 4.8

今度は名前付き let を lambda に展開する問題。一瞬どうするの?と戸惑ったけど、具体例を書いてみると (let foo ((a 1) (b 2)) (print "abc") (+ 1 a b)) を (lambda (a b) (define foo (lambda (a b) (print "abc") (+ 1 a b))) (foo 1 2)) に変換すると…

Exercise 4.5

(cond (test => recipient)) ↓ 普通の cond に変換する (cond (test (recipient test))) ↓ if に展開する。 (if test (recipient test)) と変形できるので、cond の処理は次のようになる。 (define (cond-arrow-caluse? clause) (eq? (cadr clause) '=>)) (d…

Exercise 4.7

今度は let* 式を等価の let 式に変形する問題 (define (make-let bind body) (cons 'let (cons bind body))) (define (let-parameters exp) (map car (car exp))) (define (let-arguments exp) (map cadr (car exp))) (define (let-bind exp) (cadr exp)) (…