4 ms·
One advantage of syntactic tail calls is that you can give an error if you are unable to transform to a tail call. Otherwise, you could have a program that see
by RcouF1uZ4gsC 4y ago
One advantage of syntactic tail calls is that you can give an error if you are unable to transform to a tail call.
Otherwise, you could have a program that seems to work file, and then you refactor and now your recursion isn’t a tail call anymore, and your stack blows up.
- ape4 4y agoPerhaps with a syntax for tail calls, you could do it not at the end of a function.
- richdougherty 4y agoIt needs to be at the end of the calling function so you can throw the calling function's stack frame away, since it's still in use. Getting rid of the calling stack frame is what proper tail calls is about.
- ape4 4y agoI was suggesting something like bash `exec`
- frou_dh 4y agoI thought the @tailcall annotation in OCaml was cool. It's not essential to use it to receive the optimisation, but rather it's a way to tell the compiler "I need this call to be optimised, so let me know if you can't do it".
- erik_seaberg 4y agoNice! Scala has @tailrec but I think it only checks that a function’s calls to itself are tail calls.
- mst 4y agohttps://reviews.llvm.org/D99517 https://reviews.llvm.org/D99517 is really quite interesting.