bytecompiler and tail recursion

Zajcev Evgeny zevlg at yandex.ru
Fri Oct 8 07:02:51 EDT 2004


Hello XEmacs hackers!

I've got next function:

    (defun my-fun (a lst)
      (cond ((null lst) a)
    	(t
    	 (setcar a (+ (car a) (caar lst)))
    	 (setcdr a (+ (cdr a) (cdar lst)))
    	 (my-fun a (cdr lst)))))

    (byte-compile 'my-fun)

Then i did

    (my-fun '(0 .  0) (mapcar (lambda (nu)
    			 (cons (random 10) (random 10)))
    		       (make-list 1500 nil)))

And got "Lisp nesting exceeds `max-lisp-eval-depth'" error, having
default `max-lisp-eval-depth' value (1000).

So, here is my question, why bytecompiler did not compliled `my-fun'
as tail recursion function?  It is obvious that `my-fun' is tail
recursive and can be easily expanded to loop.

Yes i know that it(`my-fun') can be easily rewritten avoiding
recursion, but it is not the way out for me.

Thanks!

-- 
lg




More information about the XEmacs-Beta mailing list