Find limit of recursion: Difference between revisions

Content added Content deleted
Line 1,429:
</pre>
This is because the Parrot VM currently imposes a limit of 1000. On the other hand, the niecza implementation has no limit, subject to availability of virtual memory. In any case, future Perl&nbsp;6 is likely to require tail call elimination in the absence of some declaration to the contrary.
 
=={{header|Phix}}==
On a 32-bit version the limit is an impressive 34 million. Of course on real word apps with more parameters etc it will be smaller. Unfortunately other problems are stopping me from testing this on a 64-bit version right now.
<lang Phix>atom t1 = time()+1
 
integer depth = 0
 
procedure recurse()
if time()>t1 then
?depth
t1 = time()+1
end if
depth += 1
-- only 1 of these will ever get called, of course...
recurse()
recurse()
recurse()
end procedure
 
recurse()</lang>
{{out}}
<pre>
C:\Program Files (x86)\Phix>p e01
8336837
16334140
20283032
21863323
22547975
22875708
23227196
23536921
24051004
24902668
25518908
26211370
26899260
27457596
27946743
28627343
29129830
29811260
31081002
31893231
32970812
33612604
34624828
34886703
Your program has run out of memory, one moment please
C:\Program Files (x86)\Phix\e01.exw:48 in procedure recurse()
memory allocation failure
... called from C:\Program Files (x86)\Phix\e01.exw:48 in procedure recurse()
... called from C:\Program Files (x86)\Phix\e01.exw:48 in procedure recurse()
... called from C:\Program Files (x86)\Phix\e01.exw:48 in procedure recurse()
... called from C:\Program Files (x86)\Phix\e01.exw:48 in procedure recurse()
 
Global & Local Variables
 
--> see C:\Program Files (x86)\Phix\ex.err
Press Enter...
C:\Program Files (x86)\Phix>
</pre>
It takes about 25 seconds to build that stack and slightly longer to tear it down. You should also note that somewhat less clean error reports are likely: even the above could theoretically fail mid-sprintf and hence exercise a completely different error handling path, and there are likely to be several hundred different ways to fail when there is no more memory.
 
=={{header|PHP}}==