Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>As you say, tail recursion is a special case of a tail call. Consequently, any language that implements general TCO trivially is "properly tail recursive".</p> <p>The inverse, however, does not hold. There are quite a few languages that only optimise tail recursion, because that is significantly easier -- you can translate it away into a loop directly, and don't need a specific "tail call" operation that manipulates the stack in new ways. For example, that is the reason why languages compiling to the JVM, which doesn't have a tail call instruction, typically only optimise tail (self) recursion. (There are techniques to work around the lack of such an instruction, e.g. trampolines, but they are quite expensive.)</p> <p>Full tail call optimization does not only apply to self (or mutually) recursive calls, but to <em>any</em> calls in tail position. In particular, it extends to calls whose target is <em>not statically known</em>, e.g. when invoking a first-class function or a dynamically-dispatched method! Consequently, it requires somewhat more elaborate (though well-known) implementation techniques.</p> <p>Many functional programming techniques -- but also some popular OO patterns (see e.g. <a href="http://www.ccs.neu.edu/home/matthias/Presentations/ecoop2004.pdf" rel="noreferrer">Felleisen's ECOOP'04 presentation</a> or <a href="http://www.eighty-twenty.org/index.cgi/tech/oo-tail-calls-20111001.html" rel="noreferrer">Guy Steele's blog post</a>) -- require full TCO to actually be usable.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload