Now if you understand these, writing a iterative procedure becomes much easier: ( define ( fib-iter current next n ) ( if ( = n 0 ) current ( fib-iter next ( + current next ) ( - n 1 )))) ( define ( fib n ) ( fib-iter 0 1 n )) To test your understanding, solve this exercise in SICP: Exercise 1.11 A function f is defined by the rule that f(n) = n if n < 3 and f(n) = f(n-1) + 2f(n-2) + 3f(n-3) if n>= 3.
Answer ( define ( f-recur n ) ( cond (( < n 3 ) n ) ( else ( + ( f-recur ( - n 1 )) ( * 2 ( f-recur ( - n 2 ))) ( * 3 ( f-recur ( - n 3 )))))))