Skip to content

Instantly share code, notes, and snippets.

@manishym
Created December 23, 2011 03:54
Show Gist options
  • Save manishym/1513076 to your computer and use it in GitHub Desktop.
Save manishym/1513076 to your computer and use it in GitHub Desktop.
Factorial in lisp recursive process
(defun fact(n)
(if (<= n 1)
1
(* n (fact (- n 1)))))
SICP3> (fact 10)
0: (FACT 10)
1: (FACT 9)
2: (FACT 8)
3: (FACT 7)
4: (FACT 6)
5: (FACT 5)
6: (FACT 4)
7: (FACT 3)
8: (FACT 2)
9: (FACT 1)
9: FACT returned 1
8: FACT returned 2
7: FACT returned 6
6: FACT returned 24
5: FACT returned 120
4: FACT returned 720
3: FACT returned 5040
2: FACT returned 40320
1: FACT returned 362880
0: FACT returned 3628800
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment