3 ms·
For loops require that you allow reassignment of named variables or mutability of the underlying objects, neither of which is allowed in Erlang. Erlang variable
by KirinDave 19y ago
For loops require that you allow reassignment of named variables or mutability of the underlying objects, neither of which is allowed in Erlang. Erlang variable assignment follows a pattern matching semantic, so locals cannot be reassigned. And all values are immutable in Erlang, meaning that you can't change the value of something "Below" the covers.
Therefore, for loops are pretty much impossible unless under the covers you map to function calls. And at that point, if you have tail recursion, why not just write it that way yourself? It's almost always less code to write a tail-recursive iteration vs. an explicit iteration in a language with pattern matching.