I am trying to write a procedure that computes f by means of an iteratve process. The function f is defined by the rule that
f(n) = n, if n < 4 and
f(n) = f(n - 1) + 2f(n - 2) + 3f(n - 3) + 4f(n - 4), if n >= 4.
Here is my procedure:
(define (f n)
(define (newF temp n)
(letrec ((first (- n 1))
(second (- n 2))
(third/fourth (- n 3))
(fifth (- n 4)))
(define (d)
((if (< first 4) (set! temp (+ temp first)) (newF temp first))
(if (< second 4) (set! temp (+ temp (* second 2))) (newF temp second))
(if (< third/fourth 4) (set! temp (+ temp (* third/fourth 3) (* third/fourth 4))) (newF temp third/fourth))
(if (< fifth 4) (set! temp (+ temp (* fifth 4)))(newF temp fifth))))
(d))
temp)
(newF 0 n))
Unfortunately, when I ran (f 7), I got this error(which referred to the if statement body):
application: not a procedure;
expected a procedure that can be applied to arguments
given: #<void>
arguments...:
#<void>
#<void>
#<void>
Anyone know the reason why and how I can fix it?
See Question&Answers more detail:os