News for hackers. Stuff that matters.
Re:What if you couldn’t program with loops? by asimpletune on Monday July 15, 2019 @09:17AM (#20440477)
Pretty easy to implement tail recursion though. Sometimes it’s hard to know if a language that automatically compiles to tail recursion will even always do it.
Re:What if you couldn’t program with loops? by JD557 on Monday July 15, 2019 @09:25AM (#20440551)
> Sometimes it’s hard to know if a language that automatically compiles to tail recursion will even always do it.

I wish more languages that do not always compile to tail recursive methods had something similar to Scala's `@tailrec` annotation (which forces the compilation to fail if the tail calls cannot be optimized).

It's not a very elegant solution, but at least it works.

Re:What if you couldn’t program with loops? by 0xcde4c3db on Monday July 15, 2019 @09:31AM (#20440608)
I even convinced a C++ compiler (don't recall whether it was g++ or clang++; it might have been during a FreeBSD fling) to do TCO at one point, but I don't remember exactly how I did it and don't think the requirements are documented anywhere. It probably involved functions declared "static" (i.e. internal linkage) and with the same signature.
Re:What if you couldn’t program with loops? by dleslie on Monday July 15, 2019 @10:25AM (#20441102)
GCC does it automatically, if it's told to optimize at level 2, IIRC.

It's -foptimize-sibling-calls