Common Lisp: Why does my tail-recursive function cause a stack overflow?
问题 I have a problem in understanding the performance of a Common Lisp function (I am still a novice). I have two versions of this function, which simply computes the sum of all integers up to a given n . Non-tail-recursive version: (defun addup3 (n) (if (= n 0) 0 (+ n (addup (- n 1))))) Tail-recursive version: (defun addup2 (n) (labels ((f (acc k) (if (= k 0) acc (f (+ acc k) (- k 1))))) (f 0 n))) I am trying to run these functions in CLISP with input n = 1000000 . Here is the result [2]>