Re:Tail recursion in Python
by iitalics on Saturday March 17, 2018 @02:31PM
(#16608309)
To add onto the point about expanding stacks: What's especially nice about this feature is that it means that you don't need to tune your algorithms to be tail recursive when they could be expressed more clearly as non-tail recursion. Functions like map would actually be less efficient on average if it was tail recursive because you would need to re-iterate the list to reverse it.
[ Parent
| on HN ]
With guile and Racket, a non-linear reverse! at the end of a map is as fast as doing a non-tail-recursive map.
There are trade-offs for both. The TCO'd map is a lot faster to restore when using continuations, but is not multi-shot continuation safe.