<?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>27455</bug_id>
          
          <creation_ts>2014-11-27 11:16:46 +0000</creation_ts>
          <short_desc>[xp31[ Unary lookup: specification gaps</short_desc>
          <delta_ts>2014-12-15 01:13:37 +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>Last Call drafts</version>
          <rep_platform>PC</rep_platform>
          <op_sys>All</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="Michael Kay">mike</reporter>
          <assigned_to name="Jonathan Robie">jonathan.robie</assigned_to>
          <cc>liam</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>115614</commentid>
    <comment_count>0</comment_count>
    <who name="Michael Kay">mike</who>
    <bug_when>2014-11-27 11:16:46 +0000</bug_when>
    <thetext>@@ comments on the text flagged with &quot;@@&quot;

[76]   	UnaryLookup	   ::=   	&quot;?&quot; KeySpecifier
[53]   	KeySpecifier	   ::=   	NCName | IntegerLiteral | ParenthesizedExpr | &quot;*&quot;
UnaryLookup returns a sequence of values selected from the context item, which must be a map or array. If the context item is not a map or an array, an error is raised [err:XPTY0tbd].

@@ already raised: tbd needs to be defined.

If the KeySpecifier is not a wildcard

@@ nowhere is it said that &quot;wildcard&quot; means &quot;*&quot;

, the semantics of the UnaryLookup operator are as follows: Let KS denote the items in the sequence to which the KeySpecifier evaluates. The UnaryLookup operator is equivalent to the following expression:

for $k in KS
return .($k)

@@ This equivalence does not hold in the error case where teh context item is a function other than a map or array.

Unary lookup is used primarily in predicates (e.g. $map[?name=&apos;Mike&apos;] or with the simple mapping operator (e.g. $maps ! ?name=&apos;Mike&apos;). 

@@ In XSLT, which makes much more use of the context item, it is likely to be used much more widely, e.g &lt;xsl:sort select=&quot;?id&quot;/&gt;.

See 3.11.3.2 Postfix Lookup for the postfix lookup operator.

Examples:

?name is equivalent to .(&quot;name&quot;), an appropriate lookup for a map.
?2 is equivalent to .(2), an appropriate lookup for an array or an integer-valued map.
?($a) is equivalent to for $k in $a return .($k), allowing keys for an array or map to be passed using a variable.
?(2 to 4) is equivalent to for $k in (2,3,4) return .($k), a convenient way to return a range of values from an array.

@@ It might be worth pointing out that the function signature for array functions expects xs:integer, the supplied value is atomized, and converted to integer if it is untyped atomic. But supplying a double will give a type error. So if @id is untypedAtomic &quot;3&quot;, then ?(@id) works, but ?(@id+1) does not.

@@ It might also be worth a reminder that you get a dynamic error if the subscript is out of bounds. For example

([1,2,3], [1,2,5], [1,2])[?3 = 5] gives an error because ?3 on one of the items in the sequence fails. However, exists(([1,2,3], [1,2,5], [1,2])[?3 = 5]) might succeed because of early exit.

If the KeySpecifier is &quot;*&quot; and the context item is a map, unary lookup is equivalent to the following expression:

for $k in map:keys(.)
return .($k)

@@ We don&apos;t provide an equivalence for the case where the KeySpecifier is &quot;*&quot; and the context item is an array. I think the equivalence is

for $k in 1 to array:size(.)
return .($k)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>116081</commentid>
    <comment_count>1</comment_count>
    <who name="Liam R E Quin">liam</who>
    <bug_when>2014-12-10 01:07:09 +0000</bug_when>
    <thetext>I think all of this is editorial execpt choosing which error gets raised;
is that right?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>116293</commentid>
    <comment_count>2</comment_count>
    <who name="Jonathan Robie">jonathan.robie</who>
    <bug_when>2014-12-15 01:13:37 +0000</bug_when>
    <thetext>(In reply to Michael Kay from comment #0)

&gt; @@ already raised: tbd needs to be defined.


Done.
 
&gt; If the KeySpecifier is not a wildcard
&gt; 
&gt; @@ nowhere is it said that &quot;wildcard&quot; means &quot;*&quot;
&gt; 
&gt; , the semantics of the UnaryLookup operator are as follows: Let KS denote
&gt; the items in the sequence to which the KeySpecifier evaluates. The
&gt; UnaryLookup operator is equivalent to the following expression:
&gt; 
&gt; for $k in KS
&gt; return .($k)
&gt; 
&gt; @@ This equivalence does not hold in the error case where teh context item
&gt; is a function other than a map or array.

The sentence before this says it&apos;s an error if the context item is not a map or array:

&lt;quote&gt;
UnaryLookup returns a sequence of values selected from the context item, which must be a map or array. If the context item is not a map or an array, a dynamic type error is raised [err:XPTY0004].
&lt;/quote&gt;

&gt; Unary lookup is used primarily in predicates (e.g. $map[?name=&apos;Mike&apos;] or
&gt; with the simple mapping operator (e.g. $maps ! ?name=&apos;Mike&apos;). 
&gt; 
&gt; @@ In XSLT, which makes much more use of the context item, it is likely to
&gt; be used much more widely, e.g &lt;xsl:sort select=&quot;?id&quot;/&gt;.

I deleted the word &quot;primarily.
 
&gt; See 3.11.3.2 Postfix Lookup for the postfix lookup operator.
&gt; 
&gt; Examples:
&gt; 
&gt; ?name is equivalent to .(&quot;name&quot;), an appropriate lookup for a map.
&gt; ?2 is equivalent to .(2), an appropriate lookup for an array or an
&gt; integer-valued map.
&gt; ?($a) is equivalent to for $k in $a return .($k), allowing keys for an array
&gt; or map to be passed using a variable.
&gt; ?(2 to 4) is equivalent to for $k in (2,3,4) return .($k), a convenient way
&gt; to return a range of values from an array.
&gt; 
&gt; @@ It might be worth pointing out that the function signature for array
&gt; functions expects xs:integer, the supplied value is atomized, and converted
&gt; to integer if it is untyped atomic. But supplying a double will give a type
&gt; error. So if @id is untypedAtomic &quot;3&quot;, then ?(@id) works, but ?(@id+1) does
&gt; not.

OK.  I added these examples.

&gt; @@ It might also be worth a reminder that you get a dynamic error if the
&gt; subscript is out of bounds. For example
&gt; 
&gt; ([1,2,3], [1,2,5], [1,2])[?3 = 5] gives an error because ?3 on one of the
&gt; items in the sequence fails. However, exists(([1,2,3], [1,2,5], [1,2])[?3 =
&gt; 5]) might succeed because of early exit.

I added the first part of this but not the second.

&gt; @@ We don&apos;t provide an equivalence for the case where the KeySpecifier is
&gt; &quot;*&quot; and the context item is an array. I think the equivalence is
&gt; 
&gt; for $k in 1 to array:size(.)
&gt; return .($k)

Ouch! Back when arrays were maps, the old equivalence worked, but this did need fixing. Done now.</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>