(wat-aro)

生きてます

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

SICP 問題 3.49

ある口座の内容によって次にアクセスする口座の内容がかわるような状況. 具体的な状況は思い浮かばず.

SICP 問題 3.48

;; make-accountの引数にidを追加. ;; dispatchの引数に'numberで口座番号を参照できる. (define (make-account-and-serializer balance id) (define (withdraw amount) (if (>= balance amount) (begin (set! balance (- balance amount)) balance) "Insu…

SICP 問題 3.47

#| このような形でmake-semaphoreは使われる. |# (define (make-serializer) (let ((semaphore (make-semaphore 6))) (lambda (p) (define (serialized-p . args) (semaphore 'acquire) (let ((val (apply p args))) (semaphore 'release) val)) serialized…

SICP 問題 3.46

cellがfalseの時に複数のプロセスが同時にcellにアクセスすればmutexは破られる

SICP 問題 3.45

serializerが入れ子になるために無限ループする

SICP 問題 3.44

(define (transfer from-account to-account amount) ((from-account 'withdraw) amount) ((to-account 'deposit) amount)) 交換と違い,残高の差を計算する必要がないので問題はおきない

SICP 問題 3.43

deposit,withdrawが直列化されてない場合, 書き換えられる前の値を参照したまま変更後の値をsetしてしまうために残高の合計が保存されない場合が有る.

SICP 問題 3.42

安全な変更.並列性の間に違いはない.

SICP 問題 3.41

変更箇所は書き換えによる変更を行わないのでそのままでも害はないので賛成しない.

SICP 問題 3.40

10^2,10^3,10^4,10^5,10^6が取り得る値となる. 直列かするとこのうち,10^6のみが残る.

SICP 問題 3.39

101:P1がxに100をセットしてから,P2がxに101をセットする 121:P2がxに11をセットしてから,P1がxに121をセットする 100:P1がxから10をとってきて,そこでP2がxに11をセット,P1が続きの(* 10 10)を計算してxに100をセットする

SICP 3.4.2 parallel-executeの実装

これ以降やるための準備です. gauche.threadsの使い方がわからなかったのでリファレンス見ながらググって見つけたコードを理解しました. (use gauche.threads) (define (delay time proc) (lambda () (thread-sleep! time) (proc))) (define (delay-print …

SICP 問題 3.38

(define balance 100) ;; Peter (set! balance (+ balance 10)) ;; Paul (set! balance (- balance 20)) ;; Mary (set! balance (- balance (/ balance 2))) ;;a 3つのプロセスがある順序で逐次的に実行された場合のbalanceの取り得る値 ;;35,40,45,50 ;;b …

SICP 問題 3.37

(define (c+ x y) (let ((z (make-connector))) (adder x y z) z)) (define (c- x y) (let ((z (make-connector))) (adder x z y) z)) (define (c* x y) (let ((z (make-connector))) (multiplier x y z) z)) (define (c/ x y) (let ((z (make-connector))) …

SICP 問題 3.36

(define a (make-connector)) (define b (make-connector)) (set-value! a 10 'user) set-value!を評価している間で (foreach-except setter inform-about-value constraints) が評価される環境を示す環境図を書け.

SICP 問題 3.35

平方器を新しい基本制約として定義する. (define (squarer a b) (define (process-new-value) (if (has-value? b) (if (< (get-value b) 0) (error "square less than 0 -- SQUARER" (get-balue b)) (set-value! a (sqrt b) me)) (set-value! b (square a) …

SICP 問題 3.34

平方器をmultiplierを使って実装する時の問題点 (define (make-connector) (let ((value false) (informant false) (constraints '())) (define (set-my-value newval setter) (cond ((not (has-value? me)) (set! value newval) (set! informant setter) (f…

SICP 問題 3.33

入力として三つのコネクタa,b,cをとり,cの値がaとbの値の平均であるような制約を達成する手続きaverager. adderとmultiplierを繋ぐコネクタをp. 定数2に繋がるコネクタをxとした. (define (averager a b c) (let ((x (make-connector)) (p (make-connector…