Why does a recursive call cause StackOverflow at different stack depths?

I think it may be ASLR at work. You can turn off DEP to test this theory. See here for a C# utility class to check memory information: https://stackoverflow.com/a/8716410/552139 By the way, with this tool, I found that the difference between the maximum and minimum stack size is around 2 KiB, which is half a … Read more

Functional Programming – Lots of emphasis on recursion, why?

Church Turing thesis highlights the equivalence between different computability models. Using recursion we don’t need a mutable state while solving some problem, and this make possible to specify a semantic in simpler terms. Thus solutions can be simpler, in a formal sense. I think that Prolog shows better than functional languages the effectiveness of recursion … Read more

foldl is tail recursive, so how come foldr runs faster than foldl?

Welcome to the world of lazy evaluation. When you think about it in terms of strict evaluation, foldl looks “good” and foldr looks “bad” because foldl is tail recursive, but foldr would have to build a tower in the stack so it can process the last item first. However, lazy evaluation turns the tables. Take, … Read more

Are any JavaScript engines tail call (TCO) optimized? [duplicate]

The ECMAScript 4 specification was originally going to add support for TCO, but it was dropped: No more tail calls in JavaScript? As far as I know, no widely-available implementations of JavaScript currently do automatic TCO. This may be of use to you, though: Tail Call Optimization Essentially, using the accumulator pattern accomplish the same … Read more

Are functions in JavaScript tail-call optimized?

Update: As of January 1, 2020 Safari is the only browser that supports tail call optimization. The chromium team explicitly states that Tail Call Optimization is not under active development and can be tracked here. The implementation for Firefox can be tracked here Original Post Yes, ES2015 offers tail call optimization in strict mode. Dr. … Read more