In Lisp, local variables must be explicitly declared using LET or other forms that create local variables. This is different from, for example, Python or JavaScript, where assigning a variable creates a variable in the current lexical domain.
Your example can be rewritten as follows:
(defun it-fact(num) (let ((result 1)) (dotimes (i num) (setf result (* result (+ i 1))))))
An off-topic comment: it makes no sense to put closing parentheses on separate lines.
dmitry_vk
source share