I am studying the awesome book SICP. Despite being great, it is a really tough book. I am having problems with the long tail recursion,id est, a recursion definition for an iterative process. The book presents this iterative procedure for factorial:
(define (factorial n)
(fact-iter 1 1 n))
(define (fact-iter product counter max-count)
(if (> counter max-count)
product
(fact-iter (* counter product)
(+ counter 1)
max-count)))
I tried doing one approach without looking at the book example. I got this:
(define (factorial n)
(factorial-iter n 1 n))
(define (factorial-iter a product counter)
(if (= counter 0)
product
(factorial-iter (- a 1)
(* product a)
(- counter 1))))
Is my approach wrong in some sense?