[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: How is memory allocated in recursive XSLT template

Subject: Re: How is memory allocated in recursive XSLT templates?
From: "Rashmi Rubdi" <rashmi.sub@xxxxxxxxx>
Date: Wed, 2 May 2007 16:29:49 -0400
Re:  How is memory allocated in recursive XSLT template
Hi Michael,

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.

Thank you for clearing my doubts of infiniteness with Recursion.

-Regards
Rashmi

On 5/2/07, Michael Kay <mike@xxxxxxxxxxxx> wrote:
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

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.