<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://www.w3.org/Bugs/Public/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4"
          urlbase="https://www.w3.org/Bugs/Public/"
          
          maintainer="sysbot+bugzilla@w3.org"
>

    <bug>
          <bug_id>17600</bug_id>
          
          <creation_ts>2012-06-26 11:55:23 +0000</creation_ts>
          <short_desc>[XQ31ReqUC] Range predicates</short_desc>
          <delta_ts>2014-05-20 16:59:31 +0000</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>XPath / XQuery / XSLT</product>
          <component>Requirements for Future Versions</component>
          <version>Working drafts</version>
          <rep_platform>PC</rep_platform>
          <op_sys>Linux</op_sys>
          <bug_status>NEW</bug_status>
          <resolution></resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="John Snelson">john.snelson</reporter>
          <assigned_to name="Jim Melton">jim.melton</assigned_to>
          <cc>jim.melton</cc>
    
    <cc>mike</cc>
          
          <qa_contact name="Mailing list for public feedback on specs from XSL and XML Query WGs">public-qt-comments</qa_contact>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>69400</commentid>
    <comment_count>0</comment_count>
    <who name="John Snelson">john.snelson</who>
    <bug_when>2012-06-26 11:55:23 +0000</bug_when>
    <thetext>Users often need to select a subsequence of a given sequence, for instance, when paginating or sampling a sequence of data. Currently we have the fn:subsequence() function which can do this:

fn:subsequence($seq,1,10)

However after using positional predicates, users are often surprised that the following intuitive syntax does not work:

$seq[1 to 10]

Indeed this is such a useful shorthand that MarkLogic already implements it as an extension to XQuery. I think it would be good to standardize this usage and make it available to other XQuery users.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>69405</commentid>
    <comment_count>1</comment_count>
    <who name="Michael Kay">mike</who>
    <bug_when>2012-06-26 12:20:52 +0000</bug_when>
    <thetext>The proposed syntax was in an early draft of XQuery and was removed because the semantics are so convoluted. To retain orthogonality, we have to allow any sequence of integers to be used as a predicate, and then we get issues about what happens when the integers in this sequence are not monotonically increasing or contain duplicates, and messy problems if the predicate is supplied in a form such as [1 to @max] where the value of @max depends on the context item. It&apos;s not hard to write [position() = 1 to 10] and I suggest we leave it that way.

However, there&apos;s another form of range predicate that would be very useful, namely selecting all items in a sequence up to (and optionally including) the first one that satisfies some condition: something like

$sequence [[from|after]] condition [[to|before] condition]]

including the possibility of

$sequence from position()=3 to position()=5

but more usefully things like

$sequence before self::h1

or

$sequence after self::h1 before self::h2</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>69408</commentid>
    <comment_count>2</comment_count>
    <who name="John Snelson">john.snelson</who>
    <bug_when>2012-06-26 13:18:06 +0000</bug_when>
    <thetext>Really, I don&apos;t know how you can call the semantics convoluted. You&apos;ve given the perfect syntactic expansion yourself:

$seq[1 to 10] === $seq[position() = (1 to 10)]

There isn&apos;t a problem with sequences with holes in - it still means the same thing.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>69409</commentid>
    <comment_count>3</comment_count>
    <who name="Michael Kay">mike</who>
    <bug_when>2012-06-26 13:26:14 +0000</bug_when>
    <thetext>&gt;$seq[1 to 10] === $seq[position() = (1 to 10)]

For what class of predicates does this equivalence hold? Any predicate whose value is a sequence of integers? Does it have to be the same sequence of integers for every node in the sequence?

Or does it only apply to an expression written syntactically as a RangeExpr? That would be a horrible breach of orthogonality.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>69410</commentid>
    <comment_count>4</comment_count>
    <who name="John Snelson">john.snelson</who>
    <bug_when>2012-06-26 13:27:43 +0000</bug_when>
    <thetext>&gt; For what class of predicates does this equivalence hold? Any predicate whose
&gt; value is a sequence of integers? Does it have to be the same sequence of
&gt; integers for every node in the sequence?

For any sequence of numeric values.

&gt; Or does it only apply to an expression written syntactically as a RangeExpr?
&gt; That would be a horrible breach of orthogonality.

Agreed.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>69413</commentid>
    <comment_count>5</comment_count>
    <who name="Michael Kay">mike</who>
    <bug_when>2012-06-26 13:43:20 +0000</bug_when>
    <thetext>&gt;For any sequence of numeric values.

Does it have to be a sequence of numeric values for every item in the input?

$seq[if (f(.)) then number(@min) to number(@max) else is-married(.)]

I think the overloading of predicates is bad enough already without introducing this.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>69415</commentid>
    <comment_count>6</comment_count>
    <who name="John Snelson">john.snelson</who>
    <bug_when>2012-06-26 14:50:31 +0000</bug_when>
    <thetext>(In reply to comment #5)
&gt; Does it have to be a sequence of numeric values for every item in the input?

No.

&gt; $seq[if (f(.)) then number(@min) to number(@max) else is-married(.)]
&gt; 
&gt; I think the overloading of predicates is bad enough already without introducing
&gt; this.

It might be slightly more complicated to evaluate, but it&apos;s actually extremely useful to users. The full semantics of a predicate expression &quot;SEQ[PRED]&quot; under this proposal could be expressed as such:

for $s at $p in SEQ
where
  typeswitch($s)
  case op:numeric+ return $p = $s
  default return fn:boolean($s)
return $s

This is not a very big departure from the present semantics:

for $s at $p in SEQ
where
  typeswitch($s)
  case op:numeric return $p eq $s
  default return fn:boolean($s)
return $s</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>69419</commentid>
    <comment_count>7</comment_count>
    <who name="Michael Kay">mike</who>
    <bug_when>2012-06-26 15:57:44 +0000</bug_when>
    <thetext>&gt;for $s at $p in SEQ
where
  typeswitch($s)
  case op:numeric+ return $p = $s
  default return fn:boolean($s)
return $s

Surely not? It depends on the type of PRED, rather than the type of $s. It must be something like this:

for $s at $p in SEQ
where
  typeswitch($s/(PRED))
  case op:numeric+ return $p = $s/(PRED)
  default return fn:boolean($s/(PRED))
return $s</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>69420</commentid>
    <comment_count>8</comment_count>
    <who name="John Snelson">john.snelson</who>
    <bug_when>2012-06-26 16:00:54 +0000</bug_when>
    <thetext>(In reply to comment #7)
&gt; Surely not? It depends on the type of PRED, rather than the type of $s. It must
&gt; be something like this:
&gt; 
&gt; for $s at $p in SEQ
&gt; where
&gt;   typeswitch($s/(PRED))
&gt;   case op:numeric+ return $p = $s/(PRED)
&gt;   default return fn:boolean($s/(PRED))
&gt; return $s

Err, yes - that was a mistake.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>106482</commentid>
    <comment_count>9</comment_count>
    <who name="Jonathan Robie">jonathan.robie</who>
    <bug_when>2014-05-20 16:59:31 +0000</bug_when>
    <thetext>Assigning to future requirements per Working Group decision (https://lists.w3.org/Archives/Member/w3c-xsl-query/2012Oct/0087.html).</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>