Recursion

A function that can call itself (directly or indirectly) is called recursive.

The classic recursive function is factorial, written n!:
factorial(n) = 1 , if n = 0
n * factorial(n - 1) , otherwise.

Since Lisp is recursive, we can write factorial this way.


   (define (fact n)
     (if (= n 0)
         1
         (* n (fact (- n 1))) ) )

Contents    Page-10    Prev    Next    Page+10    Index