SICP問題3.41
(define (make-account balance) (define (withdraw amount) (if (>= balance amount) (begin (set! balance (- balance amount)) balance) "Insufficient funds")) (define (deposit amount) (set! balance (+ balance amount)) balance) (let ((protected (make-serializer))) (define (dispatch m) (cond ((eq? m 'withdraw) (protected withdraw)) ((eq? m 'deposit) (protected deposit)) ((eq? m 'balance) ; balance) ; 変更前 ((protected (lambda () balance)))) ; 直列化した (else (error "Unknown request -- MAKE-ACCOUNT" m)))) dispatch))
直列化した部分はbalanceを返すのみで代入による変更は発生しないため、Benが心配するようなシナリオはない。