recursion - Can I recursively source a TCL script indefinitely? -


i have tcl script running inside tcl shell (synopsys primetime if it's of difference). script initiated source <script> shell. script calls recursively after specific time interval has passed calling source <script> @ end of script. question bit academic: there stack-overflow issue if script keeps calling in method?

if expand question: happens when tcl script sources script? fork child process? if so, every call forks child, stack pile of processes - since source command not parallel - there no fork (from understanding).

hope question clear. thanks.

short answer: yes.

if you're using tcl 8.5 or before, you'll run out of c stack. there's code try detect , throw soft (catchable) error if do. there's (lower) limit on number of recursions can done, controllable via interp recursionlimit. note counting recursive entries core tcl script interpreter engine; it's not exactly recursion levels in script, though close.

# set recursion limit current interpreter 2000 interp recursionlimit {} 2000 

the default 1000, enough non-recursive algorithm.

in tcl 8.6, non-recursive execution engine used commands (including source). lets code use much greater recursion depths, limited how general memory have. i've run code recursion depths of on million on conventional hardware.

you'll still need raise interp recursionlimit though; default 1000 limit remains because catches more bugs (i.e., unintentional recursions) not. it's can meaningfully raise more.


Comments

Popular posts from this blog

inversion of control - Autofac named registration constructor injection -

verilog - Systemverilog dynamic casting issues -

ios - Change Storyboard View using Seague -