Find limit of recursion: Difference between revisions
Content added Content deleted
m (→{{header|AppleScript}}: →Test 3: Changed handler name to avoid confusion of authorship.) |
(Added missing parameter type to compile with Nim 1.4. Changed comment to describe behavior with this version.) |
||
Line 2,037: | Line 2,037: | ||
=={{header|Nim}}== |
=={{header|Nim}}== |
||
<lang nim>proc recurse(i): int = |
<lang nim>proc recurse(i: int): int = |
||
echo i |
echo i |
||
recurse(i+1) |
recurse(i+1) |
||
echo recurse(0)</lang> |
echo recurse(0)</lang> |
||
Compiled without optimizations (debug build), the program stops with the following message: |
|||
Compiled without optimizations it would stop after 87317 recursions. With optimizations on recurse is translated into a tail-recursive function, without any recursion limit. Instead of waiting for the 87317 recursions you compile with debuginfo activated and check with gdb: |
|||
<pre>Error: call depth limit reached in a debug build (2000 function calls). You can change it with -d:nimCallDepthLimit=<int> but really try to avoid deep recursions instead.</pre> |
|||
⚫ | |||
Compiled with option <code>-d:release</code> (release build), it terminates with a segmentation error (on Linux) after more than 673000 calls. Switching with option <code>--gc:arc</code> to “arc” memory manager, it terminates after more than 209000 calls. |
|||
Compiled with option <code>--d:danger</code> (suppressing almost all checks), it terminates with a segmentation error after more than 785000 calls. Switching to “arc” memory manager, it terminates after more than 224000 calls. |
|||
Instead of waiting for the recursions you can compile with debuginfo activated and check with gdb: |
|||
⚫ | |||
=={{header|OCaml}}== |
=={{header|OCaml}}== |