top | item 15825771

(no title)

andrew-lucker | 8 years ago

There is a whole style of programming dedicated to tail-recursion called Continuation Passing Style. It is not usually useful for programmers directly to use, because it is so complicated to read/write, but it is very useful for compilers to generate code in CPS.

If you wanted to, for example, write a new experimental functional language and reuse part of the Rust compiler to sanity check and generate the executable, then tail-recursion would be really important.

Similarly, if you create something like a parser generator and don't have tail recursion optimization, then you are going to run out of stack space before being able to parse stuff. So, there are lots of practical applications that depend on this feature too.

discuss

order

stmw|8 years ago

Ah, thanks, makes good sense. I think of "write a new experimental functional language and reuse part of the Rust compiler" as somewhat "academic", but matter of taste. But for production parsers, I think I'd try to avoid using the stack or limit the stack, anyway.