News for hackers. Stuff that matters.
Re:Tail Recursion by bjoli on Thursday December 12, 2019 @04:19AM (#21770494)
Recursion is the fundamental looping facility. Every kind of loop can be translated to recursion. That's why I think all languages that should be compiled to has it.

Translating one looping facility to another is usually very painful. Translating a looping facility to recursion is less painful :)

Edit: as an exanple: try compiling the common lisp loop macro to python for loops. I am not even sure it is possible. Compiling it to recursive functions (of which python lacks the tail recursion optimized kind) is however a pretty straightforward, but still very much nontrivial, problem.

Re:Tail Recursion by klmr on Thursday December 12, 2019 @04:31AM (#21770536)
(nonsense deleted)
Re:Tail Recursion by kd5bjo on Thursday December 12, 2019 @05:05AM (#21770675)
Python for loops aren’t actually bounded: if the iterator you’re looping over doesn’t terminate then neither will the loop. It also only calls the iterator’s next() method once per loop, so it’s possible for the body of a loop to affect future iterations by mutating the iterator.
Re:Tail Recursion by klmr on Thursday December 12, 2019 @05:10AM (#21770704)
You’re right, of course. I had completely forgotten that.
Re:Tail Recursion by bjoli on Thursday December 12, 2019 @08:38AM (#21771689)
I saw this before you deleted it, and i just wanted to say that I would much rather compile to tail recursion than a while loop, but I generally try to avoid explicit mutation (being a scheme guy)