News for hackers. Stuff that matters.
Re:Tail Call Optimization: The Musical by toast0 on Sunday January 08, 2023 @10:27AM (#34299858)
> Otherwise you'd have to explicitly code a loop where you would much rather use recursion.

The language would have to change for you to be able to code a loop. And that would have all sorts of consequences: in Erlang, preemption happens at function calls and no loops means a bounded time until you make a function call or terminate, with loops, that changes and preemption gets more difficult.

Re:Tail Call Optimization: The Musical by pessimizer on Sunday January 08, 2023 @11:00AM (#34300154)
> in Erlang, preemption happens at function calls

I didn't think this was true. The secret sauce was that Erlang preempted on reduction counts, so as a result nothing has any responsibility to yield itself.

edit: ah, literally no difference between the two in the implementation.

Re:Tail Call Optimization: The Musical by jacquesm on Sunday January 08, 2023 @12:34PM (#34301092)
That's mostly an implementation detail though, the thread switch could happen just about anywhere. Function calls are a convenient stopping point but the way the reductions are implemented in Erlang it could theoretically be done on any boundary.
Re:Tail Call Optimization: The Musical by toast0 on Sunday January 08, 2023 @01:14PM (#34301511)
It's an implementation detail, but it's very convenient and simplifying, like a lot of Erlang implementation details.

If you take out enough simplifying implementation details, you no longer have a powerful system built from simple parts.

Re:Tail Call Optimization: The Musical by jacquesm on Sunday January 08, 2023 @02:29PM (#34302228)
In this particular case though I don't think it would matter much. I've looked pretty closely at how the BEAM does it's thing and it's a work of art, this particular trade-off is more one of convenience than of necessity. But you are right that Erlang is full of such clever (and beautiful) tricks which make it a very interesting codebase to study.