2 ms·
Sure there is: it lets you express loops immutably. Rather than `state := null; while condition do: mutate-state-and-recompute-condition`, you can do `let loop
by Smaug123 7y ago
Sure there is: it lets you express loops immutably.
Rather than `state := null; while condition do: mutate-state-and-recompute-condition`, you can do `let loop(state) = if shouldContinue(condition) then loop(newState) else resultOfTheLoop`. Rely on the tail-call optimiser to compile this to a genuine imperative loop.
This looks very odd the first few times you see it, but it's much harder to get wrong.