<?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>29622</bug_id>
          
          <creation_ts>2016-05-11 12:08:00 +0000</creation_ts>
          <short_desc>[XP31] Atomization in Postfix Lookup, Unary Lookup</short_desc>
          <delta_ts>2016-06-17 10:09:32 +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>XPath 3.1</component>
          <version>Candidate Recommendation</version>
          <rep_platform>PC</rep_platform>
          <op_sys>Windows NT</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</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="Tim Mills">tim</reporter>
          <assigned_to name="Jonathan Robie">jonathan.robie</assigned_to>
          <cc>abel.braaksma</cc>
    
    <cc>andrew_coleman</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>126414</commentid>
    <comment_count>0</comment_count>
    <who name="Tim Mills">tim</who>
    <bug_when>2016-05-11 12:08:00 +0000</bug_when>
    <thetext>In 3.11.3.1 Unary Lookup we read

for $k in KS
return .($k)

and in 3.11.3.2 Postfix Lookup we read

for $e in E, $s in S return $e($s)

In neither is atomization explicit, so as written it is interpreted as:

for $k in KS
return .(fn:data($k))

and

for $e in E, $s in S return $e(fn:data($s))

Consider 

[&apos;A&apos;, &apos;B&apos;, &apos;C&apos;] ! ?([1, 2])

is interpreted as

[&apos;A&apos;, &apos;B&apos;, &apos;C&apos;] ! (for $k in ([1, 2]) return .(fn:data($k))

which causes an error since $k iterates over the single array item, and fn:data([1, 2]) is the sequence (1, 2).

Similarly

[&apos;a&apos;, &apos;b&apos;, &apos;c&apos;] ?([1, 2]))

is interpreted as

for $e in [&apos;a&apos;, &apos;b&apos;, &apos;c&apos;], $s in [1, 2] return $e(fn:data($s))

and it should fail in a similar manner.

I propse that the specification be modified to read in 3.11.3.1 Unary Lookup 

for $k in fn:data(KS)
return .($k)

and in 3.11.3.2 Postfix Lookup 

for $e in E, $s in fn:data(S) return $e($s)

The only effect is to make some queries which would otherwise return XPTY0004 return a non-error.  It affects cases where the key specfier includes arrays or elements whose typed value is a sequence.

Note that one implementation already behaves in the manner suggested.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>126565</commentid>
    <comment_count>1</comment_count>
    <who name="Michael Kay">mike</who>
    <bug_when>2016-05-24 17:18:06 +0000</bug_when>
    <thetext>I agree that we should make this change. I think the main justification is consistency: in every other case where we have an operator (or function) where one of the operands (or arguments) is required to be an atomic sequence, we atomize the operand as a whole, rather than atomizing each item in the operand individually.

For example A=B means (some $a in data(A), $b in data(B) satisfies $a eq $b); it does not mean (some $a in A, $b in B satisfies data($a) eq data($b)).

We don&apos;t have any language or machinery to say &quot;the required type of the RHS is a sequence of items S such that the result of atomizing each item in S is a single atomic value&quot;. We do have machinery to say &quot;the required type of the RHS (after applying the function conversion rules) is an atomic sequence&quot;. Let&apos;s re-use the machinery we have rather than doing something different.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>126698</commentid>
    <comment_count>2</comment_count>
    <who name="Jonathan Robie">jonathan.robie</who>
    <bug_when>2016-06-07 15:56:36 +0000</bug_when>
    <thetext>I assume you want this for both maps and arrays.  If I understand this correctly, it would allow sequences of keys in either case:

let $m := map {
  &quot;a&quot; : 1,
  &quot;b&quot; : 2
}
return $m((&quot;a&quot;, &quot;b&quot;))
=&gt; (1, 2)


[ 2, 4, 6, 8](1, 3)
=&gt; (2, 6)

The order of keys in the sequence determines the order of the result.

This seems useful.  It&apos;s probably not a hard change for implementations, but it&apos;s a significant change in behavior.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>126703</commentid>
    <comment_count>3</comment_count>
    <who name="Michael Kay">mike</who>
    <bug_when>2016-06-07 19:24:37 +0000</bug_when>
    <thetext>(In reply to Jonathan Robie from comment #2)
&gt; I assume you want this for both maps and arrays.  If I understand this
&gt; correctly, it would allow sequences of keys in either case:

No, I don&apos;t think that&apos;s an accurate description of the proposed change. 

(1) array:get($K) and map:get($K), as well as $A($K) and $M($K), all still require $K to be a single atomic value. 

(2) the lookup operator $A?$K and $M?$K already allows $K to be a sequence of atomic values.

What is changed is that in a lookup operator, $K is atomized as a whole, rather than being atomized item-by-item. This brings it into line with all other operations that expect a sequence of atomic values as an argument.

For example, suppose that @IDREFS is an attribute node of type xs:IDREFS with value &quot;A B C D&quot; -- that is, its typed value is (&quot;A&quot;, &quot;B&quot;, &quot;C&quot;, &quot;D&quot;).

And consider $M, a map {&quot;A&quot;:1, &quot;B&quot;:2, &quot;E&quot;:5}

Under the current rules, $M?(@IDREFS) is an error because it translates to 

map:get($M, (&quot;A&quot;, &quot;B&quot;, &quot;C&quot;, &quot;D&quot;))

Under the proposed rules, the same expression returns (1, 2), because it translates to

(&quot;A&quot;, &quot;B&quot;, &quot;C&quot;, &quot;D&quot;) ! map:get($M, .)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>126767</commentid>
    <comment_count>4</comment_count>
    <who name="Abel Braaksma">abel.braaksma</who>
    <bug_when>2016-06-14 16:29:09 +0000</bug_when>
    <thetext>(reclassified the bug as XP31 bug)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>126788</commentid>
    <comment_count>5</comment_count>
    <who name="Andrew Coleman">andrew_coleman</who>
    <bug_when>2016-06-17 10:09:32 +0000</bug_when>
    <thetext>At the meeting on 2016-06-14, the WG agreed to adopt the proposal in the Description.
Action A-646-06 will track this change.</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>