Re: Multivalue tail recursion?





So my question is this: does this count as tail recursion? The actual
"last operation" of the function is just repackaging the values
returned from the recursive call. Can lisp's compiler optimize this
into a loop?

Common Lisp does not promise tail call elimination of any kind, so
whether this gets optimised is entirely dependent on the
implementation. If you need it to be a loop on any implementation,
you should write it as one (indeed the LOOP macro is the absolute king
of clarity for doing something like this.


And, secondarily, is it considered naughty to use variables like
"list" and "rest" that are built-in function names?

No. Indeed since it causes Lisp-1 people to go red in the face it is
considered particularly good style. If you can cause them actually to
burst Kenny will send you a reward.

--tim


.



Relevant Pages

  • Re: Got SystemStackError exception: stack level too deep
    ... def run_function ... optimise out this "tail recursion" into a flat loop, but Ruby doesn't; ... So you need to write this as an explicit loop, ...
    (comp.lang.ruby)
  • Re: Javascript recursion limit
    ... a loop is something that repeats - that comes back to the ... An recursive function can do that, if the language allows it. ... ECMAScript does not require an implementation to have tail recursion, ...
    (comp.lang.javascript)
  • Re: Iteration in lisp
    ... recursive function can run out of stack since CL does not guarantee ... In loop you would usually only need one change. ... So using tail recursion rather than a loop can introduce bugs in complex looping constructs. ...
    (comp.lang.lisp)
  • Re: obtaining a packages functions
    ... for any third parties interested. ... no it doesn't use tail recursion. ... are usual suspects in a functional program. ... Whether you use LOOP or a functional approach is a matter of personal ...
    (comp.lang.lisp)
  • Re: Multivalue tail recursion?
    ... does this count as tail recursion? ... In theory of course the compiler can make any program into any ... functional equivalent. ... If you want it to be a loop, ...
    (comp.lang.lisp)