Racket SICP练习1.11的球拍错误

Racket SICP练习1.11的球拍错误,racket,sicp,Racket,Sicp,球拍的翻译给了我错误 在我尝试实现递归 练习1.11的功能: #lang sicp (define (f n) (cond ((< n 3) n) (else (+ f((- n 1)) (* 2 f((- n 2))) (* 3 f((- n 3))))))) (f 2) (f 5) /Users/tanveersalim/Desktop/Git/EPI/EPI/Functional/SIC

球拍的翻译给了我错误

在我尝试实现递归

练习1.11的功能:

#lang sicp

(define (f n)
  (cond ((< n 3) n)
        (else (+ f((- n 1)) 
                 (* 2 f((- n 2))) 
                 (* 3 f((- n 3)))))))

(f 2)
(f 5)

/Users/tanveersalim/Desktop/Git/EPI/EPI/Functional/SICP/chapter_1/exercise_1-11.rkt:[跑步身体]

正如其他人所指出的,您的呼叫不正确

f(-n1))
(和其他类似实例)更改为
(f(-n1))

(定义(f n)
(cond((
您在过程定义中调用的
f
不正确;括号在
f
前面,而不是后面。你的建议奏效了!
 2
 application: not a procedure;
 expected a procedure that can be applied to arguments
 given: 4
 arguments...: [none]
 context...:
(define (f n)
  (cond ((< n 3) n)
        (else (+ (f (- n 1)) 
                 (* 2 (f (- n 2))) 
                 (* 3 (f (- n 3)))))))

(f 2) ; 2
(f 5) ; 25