Jump to content

Find limit of recursion: Difference between revisions

Rename Perl 6 -> Raku, alphabetize, minor clean-up
(++ Dc)
(Rename Perl 6 -> Raku, alphabetize, minor clean-up)
Line 481:
}</lang>
With GCC 4.5, if compiled without -O2, it segfaults quickly; if <code>gcc -O2</code>, crash never happens, because the optimizer noticed the tail recursion in recur() and turned it into a loop!
 
=={{header|C++}}==
<lang cpp>
#include <iostream>
void recurse(unsigned int i)
{
std::cout<<i<<"\n";
recurse(i+1);
}
int main()
{
recurse(0);
}
</lang>
 
 
=={{header|C sharp|C#}}==
Line 518 ⟶ 501:
 
Through execution (with Mono), another user has reached 697186.
 
=={{header|C++}}==
<lang cpp>
#include <iostream>
void recurse(unsigned int i)
{
std::cout<<i<<"\n";
recurse(i+1);
}
int main()
{
recurse(0);
}
</lang>
 
=={{header|Clojure}}==
Line 724 ⟶ 723:
</pre>
With larger stack size limit I get linearly greater numbers: stack size / 128.
 
=={{header|Déjà Vu}}==
{{untested|Déjà Vu}}
<lang dejavu>rec-fun n:
!. n
rec-fun ++ n
 
rec-fun 0</lang>
This continues until the memory is full, so I didn't wait for it to finish.
Currently, it should to to almost 3 million levels of recursion on a machine with 1 GB free.
Eliminating the <code>n</code> should give over 10 million levels on the same machine.
 
=={{header|Delphi}}==
Line 781 ⟶ 769:
 
Println('Recursion Level is ' + IntToStr(level));</lang>
 
=={{header|Déjà Vu}}==
{{untested|Déjà Vu}}
<lang dejavu>rec-fun n:
!. n
rec-fun ++ n
 
rec-fun 0</lang>
This continues until the memory is full, so I didn't wait for it to finish.
Currently, it should to to almost 3 million levels of recursion on a machine with 1 GB free.
Eliminating the <code>n</code> should give over 10 million levels on the same machine.
 
=={{header|E}}==
Line 1,127 ⟶ 1,126:
{{out}}
<pre>387</pre>
 
=={{header|Haskell}}==
<lang haskell>import Debug.Trace (trace)
Line 1,745:
458
%recursion depth exception: recursion too deep while calling function 'recurse'</pre>
 
 
=={{header|Neko}}==
Line 1,953 ⟶ 1,952:
10702179
Out of memory!
</pre>
 
=={{header|Perl 6}}==
Maximum recursion depth is memory dependent. Values in excess of 1 million are easily achieved.
{{works with|Rakudo|2015.12}}
<lang perl6>my $x = 0;
recurse;
 
sub recurse () {
++$x;
say $x if $x %% 1_000_000;
recurse;
}</lang>
 
{{out}}
When manually terminated memory use was on the order of 4Gb:
 
<pre>
1000000
2000000
3000000
4000000
5000000
6000000
7000000
8000000
9000000
10000000
^C
</pre>
 
Line 2,255 ⟶ 2,225:
 
This should theoretically return the recursion limit, as the function can't be tail-optimized and there's an exception handler to return a number when an error is encountered. For this to work one has to give the Racket VM the maximum possible memory limit and wait.
 
=={{header|Raku}}==
(formerly Perl 6)
Maximum recursion depth is memory dependent. Values in excess of 1 million are easily achieved.
{{works with|Rakudo|2015.12}}
<lang perl6>my $x = 0;
recurse;
 
sub recurse () {
++$x;
say $x if $x %% 1_000_000;
recurse;
}</lang>
 
{{out}}
When manually terminated memory use was on the order of 4Gb:
 
<pre>
1000000
2000000
3000000
4000000
5000000
6000000
7000000
8000000
9000000
10000000
^C
</pre>
 
=={{header|Retro}}==
10,333

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.