Tail recursion, and limits

Mark Wieder mwieder at ahsoftware.net
Fri Apr 26 13:18:42 EDT 2013


Geoff Canyon <gcanyon at ...> writes:

> 
> So I was curious whether LC optimizes tail calls. It appears not. But even
> stranger, this code busts the recursion limits. It should only call itself
> 900 times, right?

> And am I correct that if LC optimized tail calls, then this would work
> regardless of the recursionLimit.

Yes, that should be a valid candidate for optimization.

It's a little surprising that this breaks the default recursionLimit. I
found that it breaks on the 655th iteration. So 654 iterations in 400k
leaves a bit over 600 bytes per stack frame, which seems a little excessive
for this simple function call.

-- 
 Mark Wieder
 mwieder at ahsoftware.net






More information about the use-livecode mailing list