Type the Lisp factorial definition
Type the Lisp factorial definition
Answer
(defun factorial (n) (if (= n 0) 1 (* n (factorial (- n 1)))))
defun names the function; if picks the branch. Base case: (= n 0) returns 1. Recursive step: (* n (factorial (- n 1))). Prefix form means the operator leads — (* n ...) is n times .... Same structure as the Prolog fact/2 and the Python factorial.