[SICP 연습] 118 연습. 3, 4, 5. [완성 대기]

연습 3-45


원문


Exercise 3.45. Louis Reasoner thinks our bank-account system is unnecessarily complex and error-prone now that deposits and withdrawals aren’t automatically serialized. He suggests that make-accountand-serializer should have exported the serializer (for use by such procedures as serializedexchange) in addition to (rather than instead of) using it to serialize accounts and deposits as makeaccount did. He proposes to redefine accounts as follows:
 (define (make-account-and-serializer balance) (define (withdraw amount) (if (>= balance amount) (begin (set! balance (- balance amount)) balance) "Insufficient funds")) (define (deposit amount) (set! balance (+ balance amount)) balance) (let ((balance-serializer (make-serializer))) (define (dispatch m) (cond ((eq? m 'withdraw) (balance-serializer withdraw)) ((eq? m 'deposit) (balance-serializer deposit)) ((eq? m 'balance) balance) ((eq? m 'serializer) balance-serializer) (else (error "Unknown request -- MAKE-ACCOUNT" m)))) dispatch))

Then deposits are handled as with the original make-account:
(define (deposit account amount) ((account 'deposit) amount))

Explain what is wrong with Louis’s reasoning. In particular, consider what happens when serializedexchange is called.

코드


임시로 오류가 발견되었으니 완성을 기다리세요.
방문해 주셔서 감사합니다. 도움이 되었으면 좋겠습니다.팔로우하거나 수집하거나 댓글을 달거나 좋아요를 누르는 것을 환영합니다.
본문을 수정하고 질문하기 위해 전재하려면 출처를 밝히십시오.http://blog.csdn.net/nomasp

좋은 웹페이지 즐겨찾기