이 문제는 은행 계정에 암호를 넣는 문제입니다.
처음에 셋팅한 암호를 맞게 넣으면 제대로 작동하고,
그렇지 않으면 "Incorrect password"라고 나와야합니다.

잘 되는군요.^^
간단히 처음 실행 시 암호가 맞는지 확인하는 것으로 해결하였습니다.
참조
해럴드 애빌슨, 김재우 역, <컴퓨터 프로그램의 구조와 해석>, 인사이트, 2007, pp. 294
; answer
(define (make-account balance password)
(define (withdraw amount)
(if (>= balance amount)
(begin (set! balance (- balance amount))
balance)
"Insufficient funds"))
(define (deposit amount)
(set! balance (+ balance amount))
balance)
(define (dispatch pw m)
(if (eq? pw password)
(cond ((eq? m 'withdraw) withdraw)
((eq? m 'deposit) deposit)
(else (error "Unknown request -- MAKE-ACCOUNT"
m)))
wrongpw))
(define (wrongpw amount)
"Incorrect password")
dispatch)
; execute
(define acc (make-account 100 'secret-password))
((acc 'secret-password 'withdraw) 40)
((acc 'some-other-password 'deposit) 50)
- SICP Exercise 연습문제 3.6 (0)2008/03/08
- SICP Exercise 연습문제 3.5 (0)2008/03/08
- SICP Exercise 연습문제 3.4 (0)2008/03/08
- SICP Exercise 연습문제 3.3 (0)2008/03/08
- SICP Exercise 연습문제 3.2 (0)2008/03/08
- SICP Exercise 연습문제 3.1 (0)2008/03/08
- SICP Exercise 연습문제 2장 소스 파일 (0)2008/03/03
글에 잘못된 점, 다른 점, 부족한 점이 있다면 지적해주세요.
댓글, 트랙백, 메일 모두 고맙습니다.







댓글을 달아 주세요