Re:What if you couldn’t program with loops?
by brighter2morrow on Monday July 15, 2019 @09:05AM
(#20440383)
Any languages don't implement tail-call optimizations though which makes using recursion expensive.
[ Parent
| on HN ]
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.
> 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.
GCC does it automatically, if it's told to optimize at level 2, IIRC.
It's -foptimize-sibling-calls
Re:What if you couldn’t program with loops?
by celticmusic on Monday July 15, 2019 @09:50AM
(#20440780)
I think you meant Many languages?