Subject: Re: It's A Big Language Survey
From: rpw3@rpw3.org (Rob Warnock)
Date: Wed, 29 Apr 2009 20:05:29 -0500
Newsgroups: comp.lang.lisp
Message-ID: <b5-dnWp-TIfEZGXUnZ2dnUVZ_vmdnZ2d@speakeasy.net>
gugamilare  <gugamilare@gmail.com> wrote:
+---------------
| chthon <jurgen.defu...@pandora.be> wrote:
| > If I program in Scheme then it is almost natural to use tail
| > recursion, while in Common Lisp, generally that can not be the case,
| > since this is implementation dependent. So I use LOOP fairly often.
| 
| People keep saying that tail recursion in CL is implementation
| dependent, but the only implementation that I tested that doesn't have
| tail call optimization is ECL, and I expect that to be changed. Even
| Clisp, which is not optimized, has this optimization if you compile
| the function.
+---------------

Careful! What you say is true *only* in the absence of live bindings
for dynamic variables or live dynamic contexts such as UNWIND-PROTECT,
WITHOUT-ERRORS, HANDLER-BIND, HANDLER-CASE, CATCH, etc., etc., etc.
Even CL implementations which routinely do TCO for "simple" tail calls
generally cannot do TCO across such contours!! Note that the non-TCO'able
case could be as simple as this:

    > (defun foo (*standard-output*)
        (format t "This was *not* a tail call of FORMAT!!"))

    FOO
    > (with-output-to-string (s)
	(foo s))

    "This was *not* a tail call of FORMAT!!"
    > 


-Rob

-----
Rob Warnock			<rpw3@rpw3.org>
627 26th Avenue			<URL:http://rpw3.org/>
San Mateo, CA 94403		(650)572-2607