2017-01-21 12 views
1

내가 SICP을 읽고 있어요에 "카운트 변화를"코드를 실행라도하게하고, 장에서 한 아래와 같은 코드를 언급 :는 SICP

#lang scheme 
(define (count-change amount) 
    (cc amount 5)) 

(define (cc amount kind-of-coins) 
    (cond ((= amount 0) 1) 
     ((or (< amount 0) (= kind-of-coins 0)) 0) 
     (else (+ (cc amount 
        (- kind-of-coins 1)) 
       (cc (- amount 
         (first-denomination kind-of-coins)) 
        kind-of-coins))))) 

(define (first-denomination kinds-of-icons) 
    (cond ((= kinds-of-icons) 1) 
     ((= kinds-of-icons) 5) 
     ((= kinds-of-icons) 10) 
     ((= kinds-of-icons) 25) 
     ((= kinds-of-icons) 50))) 

(count-change 100) 
내가 DrRacket에 코드를 입력

,하지만 난 실행할 수 없습니다 그것은 성공적으로, 나는 ont 시간 동안 시도되었습니다, 무엇이 잘못되었는지를 모릅니다.

enter image description here

답변

2

당신은 first-denominations에 문제가있어의 =는 인수에 대응 오류의 결과로 두 개의 피연산자를 필요로한다. 예 :

(define (first-denomination kinds-of-icons) 
    (cond ((= kinds-of-icons 1) 1) 
     ...) 
+0

Thnaks 대단히! 조용한 어리석은 실수 ... TT – scriptboy