Find limit of recursion: Difference between revisions

Content added Content deleted
(++ Dc)
(Rename Perl 6 -> Raku, alphabetize, minor clean-up)
Line 481: Line 481:
}</lang>
}</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!
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#}}==
=={{header|C sharp|C#}}==
Line 518: Line 501:


Through execution (with Mono), another user has reached 697186.
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}}==
=={{header|Clojure}}==
Line 724: Line 723:
</pre>
</pre>
With larger stack size limit I get linearly greater numbers: stack size / 128.
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}}==
=={{header|Delphi}}==
Line 781: Line 769:


Println('Recursion Level is ' + IntToStr(level));</lang>
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}}==
=={{header|E}}==
Line 1,127: Line 1,126:
{{out}}
{{out}}
<pre>387</pre>
<pre>387</pre>

=={{header|Haskell}}==
=={{header|Haskell}}==
<lang haskell>import Debug.Trace (trace)
<lang haskell>import Debug.Trace (trace)
Line 1,745: Line 1,745:
458
458
%recursion depth exception: recursion too deep while calling function 'recurse'</pre>
%recursion depth exception: recursion too deep while calling function 'recurse'</pre>



=={{header|Neko}}==
=={{header|Neko}}==
Line 1,953: Line 1,952:
10702179
10702179
Out of memory!
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>
</pre>


Line 2,255: Line 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.
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}}==
=={{header|Retro}}==