Dana Vrajitoru
C311 Programming Languages

Recursion

Control Flow

Recursion

Example

(defun factorial (n)
  (if (< n 2) 1
    (* n (factorial (- n 1)))))
(factorial 5)
-> 5 * (factorial 4)
-> 5 * 4 * (factorial 3)
-> 5*4* 3 * (factorial 2)
-> 5*4*3* 2 * (factorial 1)
-> 5*4*3*2*1 -> 120

Recursion vs Iteration