您需要做的第一件事是正确缩进代码:
(define (f-iter sum count n)
(cond ((= count (+ n 1)) sum)
((< count 3) count)
(+ (f-iter sum (- count 1) n)
(* 2 (f-iter sum (- count 2) n))
(* 3 (f-iter sum (- count 3) n))
sum))
(+ count 1)
(f-iter sum count n))
让我们用注释来注释代码:
(define (f-iter sum count n)
(cond ((= count (+ n 1)) sum)
((< count 3) count)
(+ (f-iter sum (- count 1) n) ; the syntax of COND expects
; a list with a condition as
; the first element.
; here the first element is the
; function +, which is always true.
; as such it makes no sense.
(* 2 (f-iter sum (- count 2) n))
(* 3 (f-iter sum (- count 3) n))
sum)) ; here the result of COND is not
; used anymore. It is not returned from
; f-iter.
(+ count 1) ; this result is never used.
(f-iter sum count n)) ; this calls the same function with the
; same arguments. Thus
; f-iter calls itself
; indefinitely at this point.