Find limit of recursion: Difference between revisions
Content added Content deleted
(→{{header|Julia}}: A new entry for Julia) |
|||
Line 981: | Line 981: | ||
# the arity-0 function is not only unconstrained by memory but is fast and remains fast; it requires only 360 KB (that is KB). |
# the arity-0 function is not only unconstrained by memory but is fast and remains fast; it requires only 360 KB (that is KB). |
||
# the arity-1 function is, once again, more effectively constrained by performance than by memory: the test process was terminated after 412,000 iterations simply because it had become too slow; at that point it had only consumed about 74.6 MB. |
# the arity-1 function is, once again, more effectively constrained by performance than by memory: the test process was terminated after 412,000 iterations simply because it had become too slow; at that point it had only consumed about 74.6 MB. |
||
=={{header|Julia}}== |
|||
This solution includes two versions of the function for probing recursion depth. The '''Clean''' version is perhaps more idiomatic. However the '''Dirty''' version, by using a global variable for the depth counter and minimizing the complexity of the called code reaches a significantly greater depth of recursion. |
|||
'''Clean''' |
|||
<lang Julia> |
|||
function divedivedive(d::Int) |
|||
try |
|||
divedivedive(d+1) |
|||
catch |
|||
return d |
|||
end |
|||
end |
|||
</lang> |
|||
'''Dirty''' |
|||
<lang Julia> |
|||
function divedivedive() |
|||
global depth |
|||
depth += 1 |
|||
divedivedive() |
|||
end |
|||
</lang> |
|||
'''Main''' |
|||
<lang Julia> |
|||
depth = divedivedive(0) |
|||
println("A clean dive reaches a depth of ", depth, ".") |
|||
depth = 0 |
|||
try |
|||
divedivedive() |
|||
end |
|||
println("A dirty dive reaches a depth of ", depth, ".") |
|||
</lang> |
|||
{{out}} |
|||
<pre> |
|||
A clean dive reaches a depth of 21807. |
|||
A dirty dive reaches a depth of 174454. |
|||
</pre> |
|||
=={{header|Liberty BASIC}}== |
=={{header|Liberty BASIC}}== |