[xquery-talk] XQuery error codes and rewriting

Michael Kay mhk at mhk.me.uk
Tue Feb 7 14:21:33 PST 2006

> discusses tail recursion in X-Hive and how it breaks the standards
> conformance in some really obscure cases.

I took a different decision in Saxon: if there's a need to make a dynamic
check on the type of the return value from a function, then tail call
optimization is disabled. (In fact, this particular example fails with a
static type error saying that () is an invalid return value.)

I'm not sure these cases really are obscure, I would have thought it was
very common to write a function that occasionally returns an empty sequence
when the type signature says that it shouldn't.

The spec does actually say that you're not allowed under the "errors and
optimization" provisions to avoid doing cardinality checks. I personally
think it's a bid odd to make this a special case: it was put in to stop
people reintroducing XPath 1.0 first-item semantics by the back door, so
that string(//title) would return the string value of the first title
without scanning the rest of the document to see if there are any other
titles. (This is a shame, because this is a rather important optimization,
and it could lead to a significant performance regression for some XPath 1.0

But it does seem to me that using the optimization provisions to bypass type
checking is not quite in the spirit of the language semantics. Perhaps in
time products will evolve to give the user the choice between better
diagnostics and better performance.

(Incidentally, use of the comma operator prevents tail-call optimization in
Saxon, just as other binary operators like "+" do. Must look into that...)

Michael Kay

> -----Original Message-----
> From: talk-bounces at xquery.com 
> [mailto:talk-bounces at xquery.com] On Behalf Of Martin Probst
> Sent: 07 February 2006 13:24
> To: talk at xquery.com
> Subject: Re: [xquery-talk] XQuery error codes and rewriting
> As a late follow up on this:
> http://www.martin-probst.com/archives/2006/02/07/tail-recursio
> n-in-xquery/
> discusses tail recursion in X-Hive and how it breaks the standards
> conformance in some really obscure cases. I don't think this is really
> covered by the cited spec, however I still feel that the feature is
> worth breaking the standard...
> Martin
> _______________________________________________
> talk at xquery.com
> http://xquery.com/mailman/listinfo/talk

More information about the talk mailing list