It's not a tail call because the result of the
recursive call is processed by the caller after return: when you
it's the same as
where the "," is a sequence concatenation
One way around this is to pass xyz as an extra
parameter to the recursive function call, and have the concatenation done by the
callee rather than the caller.
In fact the mechanism used for tail-call optimization
on templates handles this situation, because it relies on the code being
evaluated in push mode, where results are written to a Receiver as soon as they
are generated, which means the function/template doesn't actually do a real
concatenation. But functions don't currently work that way. So: no, it's not a
bug, just a limitation of the current design.
Attached is a self-contained, reproducible test case (it includes
Saxon 22.214.171.124j) that runs two slightly different XSL transforms. Each causes a
1) Too many nested template or function calls. The
stylesheet may be looping.
2) Exception in thread "main"
It seems to us that the function call in
the XSLT should qualify as optimizable tail recursion, but it's seems not to
be behaving that way...
Is this a Saxon bug?
Thank you in