이글루스 | 로그인  


SICP Exercise 연습문제 3.3

이 문제는 은행 계정에 암호를 넣는 문제입니다.

처음에 셋팅한 암호를 맞게 넣으면 제대로 작동하고,

그렇지 않으면 "Incorrect password"라고 나와야합니다.

 

c3

잘 되는군요.^^

 

간단히 처음 실행 시 암호가 맞는지 확인하는 것으로 해결하였습니다.

 

 

참조

해럴드 애빌슨, 김재우 역, <컴퓨터 프로그램의 구조와 해석>, 인사이트, 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)

by | 2008/03/08 19:00 | in OCW | 트랙백 | 핑백(2) | 덧글(0)

트랙백 주소 : http://NoSyu.egloos.com/tb/4208960
☞ 내 이글루에 이 글과 관련된 글 쓰기 (트랙백 보내기) [도움말]
Linked at NoSyu의 주저리 주저리 :.. at 2008/03/08 19:36

... 이 문제는 연습문제 3.3에서 만든 프로시저를 수정하여 어떤 이가 암호를 일곱 번 넘게 틀린다면 "call-the-cops"라는 말이 떠야합니다. 잘 되는군요.^^ 이 프로 ... more

Linked at NoSyu의 주저리 주저리 :.. at 2008/03/08 19:37

... 이 문제는 연습문제 3.3에서 만든 계정에 다른 이가 접근할 수 있도록 make-joint 프로시저를 만들어야 합니다. 잘 되는군요.^^ 원계정인 peter-acc의 암호는 ... more

:         :

:

비공개 덧글

◀ 이전 페이지          다음 페이지 ▶