<?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>29713</bug_id>
          
          <creation_ts>2016-06-29 10:59:50 +0000</creation_ts>
          <short_desc>Feature request: add rest parameter</short_desc>
          <delta_ts>2016-06-30 09: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>XQuery 3.2 Use Cases and Requirements</component>
          <version>Working drafts</version>
          <rep_platform>PC</rep_platform>
          <op_sys>Windows NT</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="WS Hager">wshager</reporter>
          <assigned_to name="Jonathan Robie">jonathan.robie</assigned_to>
          <cc>abel.braaksma</cc>
    
    <cc>jmdyck</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>126855</commentid>
    <comment_count>0</comment_count>
    <who name="WS Hager">wshager</who>
    <bug_when>2016-06-29 10:59:50 +0000</bug_when>
    <thetext>Request to add a rest parameter to XQuery, in the style of javascript or python. In javascript an ellipsis is used to indicate the parameter should take the remaining parameters as a list and bind them to the prefixed one. Another option would be to suffix the parameter name with an ellipsis (or other).

E.g. 

function($args ... as array(item()?)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>126856</commentid>
    <comment_count>1</comment_count>
    <who name="Michael Kay">mike</who>
    <bug_when>2016-06-29 11:21:32 +0000</bug_when>
    <thetext>Changing this to an XQuery 3.2 requirement, since we&apos;re long past accepting new requirements for XQ 3.1, especially anything as fundamental as this.

It&apos;s something that would be very nice to have (along with optional/defaultable) parameters), but it&apos;s not at all easy to achieve, given that currently it&apos;s the combination of name+arity that uniquely identifies a function, rather than the name alone.

The availability of maps and arrays in XQ 3.1 provides a workaround in terms of allowing more flexible function interfaces; for example see the fn:transform method in which all arguments are supplied as entries in a map.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>126857</commentid>
    <comment_count>2</comment_count>
    <who name="WS Hager">wshager</who>
    <bug_when>2016-06-29 11:36:04 +0000</bug_when>
    <thetext>A function would be identified as a unary one for a single rest parameter. It means there can&apos;t be another unary function of the same name. Or am I missing something?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>126858</commentid>
    <comment_count>3</comment_count>
    <who name="Michael Dyck">jmdyck</who>
    <bug_when>2016-06-29 12:47:56 +0000</bug_when>
    <thetext>(In reply to WS Hager from comment #2)
&gt; A function would be identified as a unary one for a single rest parameter.
&gt; It means there can&apos;t be another unary function of the same name.

But say there&apos;s a binary function of the same name. If you write a function call with that name and two arguments, which of the functions are you invoking?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>126859</commentid>
    <comment_count>4</comment_count>
    <who name="WS Hager">wshager</who>
    <bug_when>2016-06-29 12:54:16 +0000</bug_when>
    <thetext>I believe XQuery implementations should override functions in order of appearence, right?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>126860</commentid>
    <comment_count>5</comment_count>
    <who name="Abel Braaksma">abel.braaksma</who>
    <bug_when>2016-06-29 12:56:08 +0000</bug_when>
    <thetext>&gt; A function would be identified as a unary one for a single rest parameter.
How would you then differentiate unambiguously between different possible signatures? With this rule in mind, suppose you have two named functions declared, same name, like this, but different arities (according to your rules):

f:test := function($args ... as array(item()?) { return $args[?1] }
f:test := function($x as xs:int, $y as xs:int) {return 1 }

What will f:test(42, 42) return? 42, or 1? And what should f:test#1 return (function that takes array or function that takes item()?)? And what f:test#2? Or f:test#99 (i.e., a reference to a function with 99 args, or one with 1 arg that takes an array, or one with 100 args, with the last one taking an array)?

I&apos;m not saying it is impossible to device the syntax, but there are likely a lot of cases to consider.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>126861</commentid>
    <comment_count>6</comment_count>
    <who name="WS Hager">wshager</who>
    <bug_when>2016-06-29 12:59:34 +0000</bug_when>
    <thetext>The goal of the syntax is to enable the creation of n-ary functions in xquery, which I sorely miss. I don&apos;t think it these cases matter more that that, so IMO anything else should be an override.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>126862</commentid>
    <comment_count>7</comment_count>
    <who name="Michael Dyck">jmdyck</who>
    <bug_when>2016-06-29 13:05:58 +0000</bug_when>
    <thetext>(In reply to WS Hager from comment #4)
&gt; I believe XQuery implementations should override functions in order of
&gt; appearence, right?

No, an XQuery implementation must raise static error XQST0034 if it encounters multiple functions with the same name and number of arguments.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>126863</commentid>
    <comment_count>8</comment_count>
    <who name="WS Hager">wshager</who>
    <bug_when>2016-06-29 13:09:56 +0000</bug_when>
    <thetext>(In reply to Michael Dyck from comment #7)
&gt; No, an XQuery implementation must raise static error XQST0034 if it
&gt; encounters multiple functions with the same name and number of arguments.

In that case eXist-db is wrong...

An error is even more clear: either multiple fixed-arity functions or a single wildcard.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>126866</commentid>
    <comment_count>9</comment_count>
    <who name="Michael Dyck">jmdyck</who>
    <bug_when>2016-06-29 15:33:55 +0000</bug_when>
    <thetext>We might be able to make it work in the current model by saying that declaring a function with a rest parameter adds an infinite set of entries to the statically known function signatures and the named functions.

So Abel&apos;s example in comment 5 would be a static error, but if we ignore the fixed-arity declaration (and also the odd syntax for function decls), then the questions about named function references remain. My inclination would be that they all return the same function value. That&apos;d be simpler than fabricating an infinite set of different function values, one for each different arity.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>126868</commentid>
    <comment_count>10</comment_count>
    <who name="Abel Braaksma">abel.braaksma</who>
    <bug_when>2016-06-30 09:59:31 +0000</bug_when>
    <thetext>(In reply to Michael Dyck from comment #9)
&gt; (and also the odd syntax for function decls)
Yes, I should have mentioned it was not meant as real code, more-a-less pseudo-code, sorry for the confusion (as in XPath you cannot declare named functions, and this should be a feature of XPath, not XQuery, and be allowed irrespective of whether the function is named or not).

&gt; My inclination would be that they all return the same function value. 
You mean, for instance, that f:test#3 would return an infinite-arity function, or that we forbid f:test#3 (and the overloads) if an infinite-arity function exists?

I think, for orthogonality, it should work the same as fn:concat. Which means, there&apos;s a single signature with infinite arity (no fixed arity overloads are allowed), where, for instance, fn:concat#8 returns an eight-arity function reference. And fn:concat(&quot;foo&quot;, ?, ?, ?) returns a three-arity function reference with a single fixed parameter.</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>