; The fibonacci function uses double recursion, which ; if written naively will run very slowly. Can we ; write it using tail recursion so that it is ; as efficient as an iterative loop? ; Here's the recursive version using named let (define fibonacci1 (lambda (n) (let fib ((i n)) (cond ((= i 0) 0) ((= i 1) 1) (else (+ (fib (- i 1)) (fib (- i 2)))))))) ; Now let's try to make it tail recursive (define fibonacci2 (lambda (n) (if (= n 0) 0 (let fib ((i n) (a1 1) (a2 0)) (if (= i 1) a1 (fib (- i 1) (+ a1 a2) a1)))))) ; HOMEWORK: implement the QUICKSORT algorithm ; that sorts a list of integers into ascending order. ; Quicksort is doubly recursive. Is it possible to ; make it tail recursive?