[xquery-talk] Fold-right

W.S. Hager wshager at gmail.com
Thu Jan 12 04:21:25 PST 2017


Not sure if anyone already noticed, but there's an error in the
XPath/XQuery F&O docs, where the example implementation of array:fold will
always return an array...

More importantly, it seems to me that a textbook implementation of
fold-right was used, without the notice that this will only work in a lazy
evaluation context. If you inspect the code as eagerly evaluated, you'll
see that the array is looped over multiple times (the result is the same of
course). This makes for a very inefficient loop AFAICT, but I may be

I just discovered that Clojure doesn't even have fold-right, because it
isn't lazily evaluated (since Clojure isn't interpreted it's probably too
complicated on the JVM).

I guess for XQuery an interpreter could defer evaluation when it encounters
specific calls, but a superficial web search on this subject related to
e.g. Saxon doesn't provide specific answers, only that (understandably) the
number of performance improvements has grown over time, and perhaps
deferring evaluation is one of them. However, as I'm re-evaluating (no pun
intended) my investment in XQuery, I'm eager to hear if there are some more
theoretical grounds for providing said example, or if the committee intends
to one day provide them.

Is there any assumption about the laziness of an XQuery implementation? Are
there any a priori lazy implementations out there?

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://x-query.com/pipermail/talk/attachments/20170112/78918c37/attachment.html>

More information about the talk mailing list