Find limit of recursion: Difference between revisions

→‎{{header|Tcl}}: Updated with notes about what the real limit is
(Use of call rather than CMD/C in Batch version)
(→‎{{header|Tcl}}: Updated with notes about what the real limit is)
Line 57:
This is depth 998
This is depth 999
</pre>
Note that the maximum recursion depth is a tunable parameter, as is shown in this program:
<lang tcl># Increase the maximum depth
interp recursionlimit {} 1000000
proc recur i {
if {[catch {recur [incr i]}]} {
# If we failed to recurse, print how far we got
puts "Got to depth $i"
}
}
recur 0</lang>
For Tcl 8.5 on this platform, this prints:
<pre>
Got to depth 6610
</pre>
At which point it has exhausted the C stack. Tcl 8.6 uses a stackless execution engine, and can go ''very'' deep if required:
<pre>
Got to depth 999999
</pre>
 
Anonymous user