第162回 素人くさいSICP読書会(at 三田某所)

  • 会場提供ありがとうございました
  • 雑談が多かった
  • 4章の意義とか
    • リレーションモデルとか
    • 超循環に意味はあるかとか
  • BASICとかセンター試験とか
  • ゆきねこの人が持ってきた大堀先生の本とか

コンピュータサイエンス入門〈1〉アルゴリズムとプログラミング言語

コンピュータサイエンス入門〈1〉アルゴリズムとプログラミング言語

  • 大堀先生が頭良すぎて説明が不親切なので読む必要はないらしい
  • symbol → 記号の訳はどうかとか
  • 問題5.7
  • 基本的には問題5.4の解答をコピペするだけだが、紙に書いてたので打ち直し
  • 「テストせよ」という訳について
  • また実装がないので実行はできない
  • 外から見た仕様はほぼ同じ。valとproductの名前を合わせておくと同じようにテストできる

a.再帰的べき乗

(define recursive-expt-machine
  (make-machine
   '(b n val continue)
   (list (list '= =) (list '- -) (list '* *))
   '(
       (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 n) (const 1))
       (assign contune (label after-expt))
       (goto (label expt-loop))
    after-expt
       (restore n)
       (restore continue)
       (assign val (op *) (reg b) (reg val))
       (goto (reg continue))
    base-case
       (assign val (const 1))
       (goto (reg continue))
    expt-done)))

(set-register-contents! recursive-expt-machine 'b 2)
(set-register-contents! recursive-expt-machine 'n 3)
(start recursive-expt-machine)
(get-register-contents recursive-expt-machine 'val)  -> 8

b.反復的べき乗

(define iterative-expt-machine
  (make-machine
   '(b n counter product)
   (list (list '= =) (list '- -) (list '* *))
   '(
       (assign counter (reg n))
       (assign product (const 1))
    test-counter
       (test (op =) (reg counter) (const 0))
       (branch (label expt-done))
       (assign counter (op -) (reg counter) (const 1))
       (assign product (op *) (reg b) (reg product))
       (goto (label test-counter))
    expt-done)))

(set-register-contents! iterative-expt-machine 'b 2)
(set-register-contents! iterative-expt-machine 'n 3)
(start iterative-expt-machine)
(get-register-contents iterative-expt-machine 'product)  -> 8
  • 自転車に100万円は普通
  • ベアリングの話。ベアリング家と軸受けのベアリングは関係ないらしい