[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: [XQuery] FLWOR (for-let-where-order-return) equivalentto F


advantages of xquery
Roger L. Costello wrote:

>Hi Folks,
> 
>I am wondering about the value of the "let" and "where" clause in the XQuery
>FLWOR expression.  I believe that the same capability is possible simply by
>using a for-order-return expression.  If that is true, then I wonder about
>the value of FLWOR (recent discussions seem to imply that  FLWOR is one of
>the "key advantages" of XQuery).
>
>Let me give a couple of examples.
> 
>Example 1.  Let's start with a simple example.  Consider this XML document:
> 
><?xml version="1.0"?> 
><Numbers> 
>    <Number>0</Number> 
>    <Number>8</Number> 
>    <Number>23</Number> 
>    <Number>17</Number> 
>    <Number>5</Number> 
>    <Number>19</Number> 
>    <Number>44</Number> 
>    <Number>13</Number> 
>    <Number>78</Number> 
>    <Number>21</Number> 
>    <Number>2</Number> 
>    <Number>1</Number> 
>    <Number>15</Number> 
>    <Number>67</Number> 
>    <Number>99</Number> 
>    <Number>14</Number> 
>    <Number>8</Number> 
>    <Number>33</Number> 
>    <Number>50</Number> 
></Numbers> 
>
>Problem: output all the numbers less than 20, in ascending sorted order.
>
>Here's how to do it using for-where-order-return:
>
>for $i in //Number 
>    where number($i) <= 20 
>        order by number($i) ascending 
>            return $i/text()
>
>
>  
>
<snip/>

>Is there something that can be done with for-let-where-order-return which
>simply cannot be done with for-order-return?  If not, then what value is
>for-let-where-order-return?  Is it simply "syntactic sugar"?  /Roger 
>
>  
>
for $i in //Number 
    let $y = number($i) * number($i) in
    where number($y) <= 20 
        order by number($i) ascending 
            return $i/text()


It's possible but clumsy to achieve the same without let (imagine $y was 
something more complicated). In most programming languages, "let" and 
"where" are just there to make things more readable. If $y is used in 
several places, an advantage can be that you evaluate it only once.

There are a number of equivalences regarding for-comprehensions and 
XPath expressions - see Mary Fernandez, Jerome Simeon and Phil Wadler's 
XQuery algebra paper "A semi-monad for semistructured data". In 
principle, if one knows which alternative evaluates faster, one can use 
these equivalences for optimization.

cheers,
Burak

-- 
Burak Emir

http://lamp.epfl.ch/~buraq


PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
 

Stylus Studio has published XML-DEV in RSS and ATOM formats, enabling users to easily subcribe to the list from their preferred news reader application.


Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website. they were not included by the author in the initial post. To view the content without the Sponsor Links please click here.

Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.