Subject: Re: [xsl] How is memory allocated in recursive XSLT templates? From: "Rashmi Rubdi" <rashmi.sub@xxxxxxxxx> Date: Wed, 2 May 2007 16:29:49 -0400 |
Thank you for your reply, it is very informative. I now understand the concept of what happens with the tail recursion.
Also the fact that recursive functions can be turned into iterations is very interesting and something that's new to me, and I will take a look at that further.
-Regards Rashmi
Well, clearly implementations may differ.
At first sight you are right: recursive template calls will consume an amount of stack space proportional to the depth of recursion, and if you code goes into infinite recursion you will hit some limit on the amount of stack space available, which will cause execution to crash in some way.
However, there's a well-known optimization in functional programming languages whereby recursive calls can sometimes be turned into iterations, and if this happens then an infinite recursion can become an infinite iteration, which won't terminate due to lack of resources. This applies to functions that are "tail-recursive": basically, if the calling code doesn't need to do anything with the result of the called code, then instead of the sequence (make recursive call, then pop stack) it can do (pop stack, then make recursive call). Saxon will do this for the template in your example.
Michael Kay http://www.saxonica.com/
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] How is memory allocated i, Michael Kay | Thread | Re: [xsl] How is memory allocated i, Dimitre Novatchev |
Re: [xsl] Help moving away from nam, David Carlisle | Date | Re: [xsl] How is memory allocated i, Abel Braaksma |
Month |