Skip to content

Instantly share code, notes, and snippets.

@iomonad
Forked from manishym/factorial-recursive.lisp
Created March 3, 2018 15:18
Show Gist options
  • Save iomonad/fc8a01070180133221e526e8259b1b6f to your computer and use it in GitHub Desktop.
Save iomonad/fc8a01070180133221e526e8259b1b6f 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