さかもとのブログ

つらつらと

2009-08-03から1日間の記事一覧

SICP演習問題5.35

今回は,載っている翻訳済のコードを生み出すような式をもとめよ,という問題 翻訳済のコードは以下のもの.(SICPのサイトより抜粋) (assign val (op make-compiled-procedure) (label entry16) (reg env)) (goto (label after-lambda15)) entry16 (assign e…

SICP演習問題5.34

factorialの反復的プロセス版を翻訳する (print-after-compiler (compile '(define (factorial n) (define (iter product counter) (if (> counter n) product (iter (* counter product) (+ counter 1)))) (iter 1 1)) 'val 'next)) 結果 (env) (val) (assi…

SICP演習問題5.33

昨日のprint用の関数を少し直した. (define (print-after-compiler proc) (newline) (for-each (lambda (x) (if (not (pair? (car x))) (print x) (for-each (lambda (y) (if (symbol? y) (print y) (print " "y))) x))) proc)) 今回の問題は (define (fact…

SICP演習問題5.36, 5.37

5.36 operandsを評価するのは (define (compile-application exp target linkage) (let ((proc-code (compile (operator exp) 'proc 'next)) (operand-codes (map (lambda (operand) (compile operand 'val 'next)) (operands exp)))) (preserving '(env con…