Discussion:
[xquery-talk] lazy evaluation of sequences
Ihe Onwuka
2014-03-14 13:59:12 UTC
Permalink
does (expr1, expr2,.......,exprN)[1] and variants thereof evaluate
lazily. Is this implementation dependent.
Ihe Onwuka
2014-03-14 14:32:33 UTC
Permalink
Well (4,5 div 0)[1] on Saxon gives 4. Hurray.

(4,5 div 0)[1] in eXist gives divide by zero error. Boo.

So the answer seems to be it depends.
Post by Ihe Onwuka
does (expr1, expr2,.......,exprN)[1] and variants thereof evaluate
lazily. Is this implementation dependent.
Michael Kay
2014-03-14 16:12:48 UTC
Permalink
Post by Ihe Onwuka
Well (4,5 div 0)[1] on Saxon gives 4. Hurray.
(4,5 div 0)[1] in eXist gives divide by zero error. Boo.
So the answer seems to be it depends.
Correct, it's entirely implementation-dependent.

Saxon would fail on (4, 5 div 0, 6)[3], but other products might return 6.

The rule (see the "Errors and Optimization" section of the spec) is (my precis) that a processor doesn't have to evaluate an expression if it doesn't need to know the value of that expression in order to deliver the final result, and in particular, it never needs to evaluate an expression merely in order to discover whether evaluating it throws an error.

Michael Kay
Saxonica

Loading...