<i>some tailcall operations evade recursion limit checks</i> status still Open with 3 other changes
by
.
D 2024-02-07T17:23:18.741
J icomment Not\s"some\scircumstances"\s-\sbasically\sit\snever\stests\s<code>interp\srecursionlimit</code>:\r\n\r\n\s\s\s\s%\sinterp\srecursionlimit\s{}\r\n\s\s\s\s1000\r\n\s\s\s\s%\sproc\stest\s{{cnt\s0}}\s{\sif\s{$cnt\s>=\s1e5}\s{return\sSTOPPED};\stailcall\stest\s[incr\scnt]\s};\stest\r\n\s\s\s\sSTOPPED\r\n\r\n...\sand\sit\sis\sgood\sso\sin\smy\sopinion:\r\n\r\n\s\s-\s<code>tailcall</code>\sis\snot\sa\srecursion\sdirectly,\sbecause\sit\sbuilds\sa\sfunction\sinvocation\sstacklessly\s(replaces\sthe\scurrent\sframe\swith\sinvoked\sframe)\r\n\s\s-\smoreover\sit\sis\srather\sa\sreplacement\sfor\s(cyclic)\suplevel\scall,\sand\sas\s[its\sdocu](https://www.tcl-lang.org/man/tcl/TclCmd/tailcall.html)\ssays:<br/>\r\n\s\s*The\stailcall\scommand\s**replaces**\sthe\scurrently\sexecuting\sprocedure,\slambda\sapplication,\sor\smethod\swith\sanother\scommand*<br/>\r\n\s\sbut\salso\sas\s[its\sTIP](/../tips/doc/trunk/tip/327.md)\ssays:<br/>\r\n\s\s*The\seffect\sof\sthis\scommand\sis\svery\ssimilar\sto:<br/>\r\n\s\s\s\s<code>return\s[uplevel\s1\s[list\s[namespace\swhich\scmd\s]\s?arg\s...?]]</code><br/>\r\n\s\swith\sthe\ssole\sexception\sthat\sthe\sinvocation\sof\scmd\shappens\s**after\sthe\scurrently\sexecuting\sbody\sreturns**\sand\sis\snot\svisible\sin\sTcl's\scall\sstack.*\r\n\r\n\s\s-\sit's\sone\sof\sthe\sadvantages\sof\s<code>tailcall</code>;\r\n\r\n\s\s-\sthe\simportant\sreason\sfor\s<code>interp\srecursionlimit</code>\sis\snot\sa\sprevention\sagainst\sinfinite\sexecution\s(for\swhich\sone'd\srather\suse\s<code>interp\slimit</code>),\sbut\savoidance\sof\sstack\soverflow\sor\sOOM\ssituation\s(mostly\sbefore\sNRE\sgot\sintroduced);\r\n\r\n\s\s-\smany\scyclic\sflows\sinclusive\srecursion\sunfolded\sto\scycle\swith\sself-made\sstack\sfor\sargs\sas\slist\s(no\smatter\sNRE\sor\snot)\swould\salso\snot\simplicitly\scheck\s<code>interp\srecursionlimit</code>;\r\n\r\n\r\nWith\sother\swords,\sif\sit\sis\snot\sa\srecursion,\swhy\sshall\sit\scheck\sthe\s<code>interp\srecursionlimit</code>?
J login sebres
J mimetype text/x-markdown
K af0e43c96ee61edeea3ec666533316fb05ec9b2f
U sebres
Z 98a94940b238557b0689146df67d95ad