针对SICP练习1.11的球拍错误

时间:2018-05-15 00:08:45

标签: racket sicp

Racket的翻译给了我错误

我试图实现递归

练习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)

Racket intrepreter给出的错误是:

 2
 application: not a procedure;
 expected a procedure that can be applied to arguments
 given: 4
 arguments...: [none]
 context...:

/Users/tanveersalim/Desktop/Git/EPI/EPI/Functional/SICP/chapter_1/exercise_1-11.rkt: [running body]

1 个答案:

答案 0 :(得分:2)

正如其他人所说,您未正确调用f((- n 1))

(f (- n 1))(以及其他类似情况)更改为(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

for (i = 0; i <= task.size(); i++) 
{
    jComboBoxTask.setModel(new javax.swing.DefaultComboBoxModel<>(
       new String[]{task.get(i).getTaskName(), task.get(i + 1).getTaskName(),