factorial
(defun factorial (n)
(cond ((or (not (integerp n))
(< n 0))
(error
"argument is not a non-negative integer"))
(t (fact n))))
;;; assumes a non-negative integer
;;; computes factorial of its argument
(defun fact (arg)
(if (zerop arg)
1
(* arg (fact (1- arg))))) ; recurse
Previous slide
Next slide
Back to first slide
View graphic version