[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: tail recursion optimization
- To: DCP@QUABBIN.SCRC.Symbolics.COM, common-lisp@SU-AI.ARPA
- Subject: Re: tail recursion optimization
- From: Guy Steele <gls@Think.COM>
- Date: Tue, 10 Jun 86 10:29 EDT
- Cc: gls@AQUINAS
- In-reply-to: <860609215232.9.DCP@FIREBIRD.SCRC.Symbolics.COM>
Date: Mon, 9 Jun 86 21:52 EDT
From: David C. Plummer <DCP@QUABBIN.SCRC.Symbolics.COM>
Date: Tue, 03 Jun 86 06:27:53 PST
From: franz!fimass!jkf@kim.Berkeley.EDU (John Foderaro)
To answer earl's question: yes, a self-tail-recursive call is made
with a jump to the beginning of the function code.
I agree with Rob, this is an important optimization and 99% of the
time is it precisely what you want. I'd suggest that the Common
Lisp Standard state that within the defun of foo, there is an impliclit
(declare (inline foo))
and if the user plans on redefining foo while executing foo, it is his
burden to (declare (notinline foo)).
Inline is orthogonal to tail recursion optimization.
(defun foo (a b) (declare (inline foo)) (foo a (+ a b)))
is equivalent to
(defun foo (a b) (+a (+ a (+ a (+ a ...)))))
(defun foo (a b) (loop (psetq a a b (+ a b))))
But the latter appears to be a valid (and cleverly optimized)
implementation of the former.