ISSUE: Please consider laziness.

Summary: It is useful and good to have lazy (i.e. - call by need)
          implementations of XQuery.  The spec should consider this,
          and not accidentally forbid it.


XQuery is a query language, and as such should be designed for heavy
optimization, and partial evaluation of query results.


XQuery implementations may want to only evaluate subexpressions if
their results are actually used.  This could dramatically improve the
performance of some queries.


XQuery implementations will often want to 'stream' the results of path
and for expressions.  For example, I might have the following query:

    define function get-the-first ($set) { $set[1] }

    get-the-first ($doc//child)

If $doc is very large, and there is only a single <child> within it,
and this <child> is near the beginning of the document, it is a useful
optimization to only evaluate that part of the traversal as is needed.


Unfortunately, the XQuery specification does not seem to talk about
laziness as an option for implementations, and many parts of the spec
seem to imply that XQuery is strict (function arguments being
evaluated BEFORE function application, for example).


In particular, I worry that whatever type mechanism you design for
function parameters will force the arguments to any function to be
entirely evaluated before the function is called, which would be very
unfortunate.

For example, say I have a sophisticated, and deeply recursive type
(say 'Organization').  Then, say I have a list of them.

Say I have a function:

   define function process-orgs (element of type Organization* $org-list)
   {
     ...
   }

If I invoked this function with a list of 20,000 Organizations, to
dynamically check the type of the argument, will I have to check the
input sequence deep at function call time?  This forces its evaluation
in a profound way, and is in any case extremely expensive.


In summary, please take laziness into consideration when designing
aspects of XQuery which might be affected by such an implementation.


Thank you for your time.
       -Shawn Vincent.


--
Shawn Vincent, svincent@exalt.com
Exalt Inc.

Received on Monday, 14 January 2002 10:35:26 UTC