3 ms·
The single exit style works great in a language with TCO, nested functions and no looping primitive at all. No such language is widely available. But the style
by norir 3y ago
The single exit style works great in a language with TCO, nested functions and no looping primitive at all. No such language is widely available. But the style works really well and can be simulated in languages like scala if you ignore the while keyword and express all loops as tail recursive functions. This style does not work well in c (particularly due to the lack of nested functions) and similar languages.
It is a different way of thinking though and it takes a while before your mind stops reaching for while loops.
- trealira 3y ago> The single exit style works great in a language with TCO, nested functions and no looping primitive at all. No such language is widely available. There's Scheme. There may be constructs like DO and WHILE (though I don't remember if these are standard or just common extensions of Scheme), but they're often just macros implemented using inner functions and tail calls.