(wat-aro)

生きてます

2016-01-23から1日間の記事一覧

SICP 問題 5.08

start (goto (label here)) here (assign a (const 3)) (goto (label there)) here (assign a (const 4)) (goto (label there)) there この時thereに達した時のaの値は何かという問題. (define (extract-labels text receive) (if (null? text) (receive '(…

SICP 問題 5.07

;; シミュレータを使い問題5.04で設計した計算機をテストせよ ;; 再帰的べき乗 (define factorial-recur-machine (make-machine '(b n val continue) (list (list '* *) (list '- -) (list '= =)) '((assign continue (label expt-done)) expt-loop (test (o…

SICP 問題 5.06

Fibonacci計算機の余分なsaveとrestoreを取り除く afterfib-n-1 (restore n) (restore continue) ;ここでcontinueをrestoreしているのに (assign n (op -) (reg n) (const 2)) (save continue) ;ここでそのままcontinueをsaveして (assign continue (label a…

SICP 問題 5.05

階乗とFibonacci計算機を机上シミュレート. ;; 再帰的な階乗計算を机上シミュレートする. (controller (assign continue (label fact-done)) fact-loop (test (op =) (reg n) (const 1)) (branch (label base-case)) ;; nと continue を退避し再帰呼び出し…

SICP 問題 5.04

;; a 再帰的べき乗 (define (expt b n) (if (= n 0) 1 (* b (expt b (- n 1))))) (controller (assign continue (label expt-done)) expt-loop (test (op =) (reg n) (const 0)) (branch (label base-case)) (save continue) (save n) (assign n (op -) (reg…