Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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.



I 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".


Nice! Scala has @tailrec but I think it only checks that a function’s calls to itself are tail calls.


https://reviews.llvm.org/D99517 is really quite interesting.


Perhaps with a syntax for tail calls, you could do it not at the end of a function.


It 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.


I was suggesting something like bash `exec`




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: