Timeline for What can qualify for potential tail call recursion (TCO) optimization or tail recursion elimination (TRE)
Current License: CC BY-SA 3.0
4 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Nov 15, 2023 at 23:30 | comment | added | gnasher729 | You could have a function timesfactorial(x, n) which returns x * n! That function could call timesfactorial (x*n, n-1) which is tail recursive. | |
| Jan 10, 2016 at 17:54 | comment | added | Deduplicator | @Ixrec: A good optimizers might sometimes inline a call, tail-call or not, and/or replace recursion with a loop. | |
| Jan 10, 2016 at 17:50 | comment | added | Ixrec |
I'm trying to think of any way an aggressively optimizing compiler could do better, but it does seem like this is probably about it. The best I can come up with is that in the return n+f(); case, maybe the compiler could keep an int hanging around that it adds n to on every f() call because it knows that n+...+n+f() reduces to xn+f() and that last addition can wait until the final f() call. But that seems unlikely to be worth the effort.
|
|
| Jan 10, 2016 at 17:29 | history | answered | Bart van Ingen Schenau | CC BY-SA 3.0 |