From: Teemu Likonen <tlikonen@ik...>  20110713 17:38:34

* 20110614T19:53:36+03:00 * Nikodemus Siivola wrote: > On 14 June 2011 19:38, Cheung, Matthew G <mgcheung@...> wrote: >> One thing that has never been clear to me was whether SBCL will by >> default use tail recursion optimisations. I wrote a general >> "repeated > > Tailmerging is done if (> SPACE DEBUG) or (> SPEED DEBUG)  not by > default. Is the TRACE output a reliable way to tell whether optimization on recursive calls has occurred? See the following toy example. It is recursive but, if I understand correctly, there is no tailcall. Without much speed optimization: (defun sum (numbers) (declare (optimize (speed 0) (debug 0))) (if numbers (+ (first numbers) (sum (rest numbers))) 0)) CLUSER> (trace sum) (SUM) CLUSER> (sum '(1 2 3 4)) 0: (SUM (1 2 3 4)) 1: (SUM (2 3 4)) 2: (SUM (3 4)) 3: (SUM (4)) 4: (SUM NIL) 4: SUM returned 0 3: SUM returned 4 2: SUM returned 7 1: SUM returned 9 0: SUM returned 10 10 Now the same thing with more speed: (defun sum (numbers) (declare (optimize (speed 3) (debug 0))) (if numbers (+ (first numbers) (sum (rest numbers))) 0)) CLUSER> (sum '(1 2 3 4)) 0: (SUM (1 2 3 4)) 0: SUM returned 10 10 It seems that the was only one call to SUM so either there is some optimization or TRACE couldn't track what's really happening. 