4 ms·
Most dynamic languages including Scheme have unlimited recursion (limited only by total memory). Once you've gotten used to being able to use recursion, stack
by tlb 4y ago
Most dynamic languages including Scheme have unlimited recursion (limited only by total memory).
Once you've gotten used to being able to use recursion, stack depth limits seem as lame as olden-days limits on string length (255 characters was common in Pascal).
Javascript is a frustrating case where unlimited recursion is technically possible in modern engines, but they still often limit it to 10000 or something.
Python limits it arbitrarily, just to force you to use its fancy iteration system.
- adenozine 4y agoIt’s not quite arbitrarily. That’s an uncharitable definition. Python a) handles function arguments in a way that would make recursive functions awkward to use and b) cares about stacktraces being meaningful, so TCO would be a worse tradeoff towards that end as well. There’s trampolines in almost any programming language to implement recursion if necessary, and python has itertools to build what Scheme calls streams, for arbitrary computation.
- dragonwriter 4y ago> Python limits it arbitrarily, just to force you to use its fancy iteration system. Python has an arbitrary and low default limit because it isn’t optimized (because stack traces are considered important), abd call depth is an effifiency issue that risks blowing up without a limim because of stack depth, and failing fast in the likely-erroneous case of deep call stack given all that is just sensible. Python also. Lets you alter the limit at runtime; ita a soft, not hard, limit. The hard limit is stack space.
- tlb 4y agoPeople often talk about accidental infinite recursion, but that seems like a rare mistake. I might have done it twice in a 40 year career? It's much rarer than an accidental infinite loop, which (almost) no language tries to protect you against. It doesn't seem worth giving up useful recursion. Python's "solution" requires changing a global, which is an ugly thing for a library that wants to recurse to do.
- versteegen 4y agoYou or the code you write must be extremely unusual. I might have blown the stack a thousand times, in many different languages. Probably most of the time I wasn't intentionally recursing at all.