Skip to content

Commit

Permalink
Merge pull request #1137 from michaelhkay/161-variadic-functions
Browse files Browse the repository at this point in the history
161 Variadic functions
  • Loading branch information
michaelhkay authored Apr 30, 2024
2 parents 22339f0 + 78182c9 commit ad2bdcb
Show file tree
Hide file tree
Showing 8 changed files with 611 additions and 330 deletions.
1 change: 1 addition & 0 deletions specifications/xpath-functions-40/src/fos.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@
<xs:enumeration value="context-independent"/>
<xs:enumeration value="higher-order"/>
<xs:enumeration value="special-streaming-rules"/>
<xs:enumeration value="variadic"/>
</xs:restriction>
</xs:simpleType>
<xs:element name="summary">
Expand Down
56 changes: 35 additions & 21 deletions specifications/xpath-functions-40/src/function-catalog.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3727,6 +3727,7 @@ translate(value := '٢٠٢٣', replace := '٠١٢٣٤٥٦٧٨٩', with := '01234
<fos:property>deterministic</fos:property>
<fos:property>context-independent</fos:property>
<fos:property>focus-independent</fos:property>
<fos:property>variadic</fos:property>
</fos:properties>
<fos:summary>
<p>Returns an <code>xs:string</code> whose characters have supplied <termref
Expand All @@ -3738,6 +3739,9 @@ translate(value := '٢٠٢٣', replace := '٠١٢٣٤٥٦٧٨٩', with := '01234
>codepoints</termref> are
supplied in <code>$values</code>. This will be the zero-length string if <code>$values</code>
is the empty sequence. </p>
<p>In 4.0 the function is declared to be variadic, so the call
<code>codepoints-to-string(66, 65, 67, 72)</code> is now equivalent to
<code>codepoints-to-string((66, 65, 67, 72))</code>.</p>

</fos:rules>
<fos:errors>
Expand All @@ -3753,7 +3757,15 @@ translate(value := '٢٠٢٣', replace := '٠١٢٣٤٥٦٧٨٩', with := '01234
<fos:result>"BACH"</fos:result>
</fos:test>
<fos:test>
<fos:expression>codepoints-to-string((2309, 2358, 2378, 2325))</fos:expression>
<fos:expression>codepoints-to-string(66, 65, 67, 72)</fos:expression>
<fos:result>"BACH"</fos:result>
</fos:test>
<fos:test>
<fos:expression>codepoints-to-string((66, 65), (67, 72))</fos:expression>
<fos:result>"BACH"</fos:result>
</fos:test>
<fos:test>
<fos:expression>codepoints-to-string(2309, 2358, 2378, 2325)</fos:expression>
<fos:result>"अशॊक"</fos:result>
</fos:test>
<fos:test>
Expand Down Expand Up @@ -4131,7 +4143,7 @@ translate(value := '٢٠٢٣', replace := '٠١٢٣٤٥٦٧٨٩', with := '01234
<fos:function name="concat" prefix="fn">
<fos:signatures>
<fos:proto name="concat" return-type="xs:string">
<fos:arg name="..." type="xs:anyAtomicType*"/>
<fos:arg name="values" type="xs:anyAtomicType*" default="()"/>
</fos:proto>
</fos:signatures>
<fos:opermap operator="||" types="xs:anyAtomicType xs:anyAtomicType"
Expand All @@ -4141,30 +4153,29 @@ translate(value := '٢٠٢٣', replace := '٠١٢٣٤٥٦٧٨٩', with := '01234
<fos:property>deterministic</fos:property>
<fos:property>context-independent</fos:property>
<fos:property>focus-independent</fos:property>
<fos:property>variadic</fos:property>
</fos:properties>
<fos:summary>
<p>Returns the concatenation of the string values of the arguments.</p>
</fos:summary>
<fos:rules>
<p>This function accepts zero or more arguments, each declared with the required type
<code>xs:anyAtomicType*</code>. The value <code>$v</code> supplied for each argument
is first reduced to a single string as follows:</p>
<ulist>
<item>
<p>If XPath 1.0 compatibility mode is set to true in the static context of the
function call, then the result of <code>xs:string($v[1])</code>.</p>
</item>
<item>
<p>Otherwise, the result of <code>fn:string-join($v)</code>.</p>
</item>
</ulist>
<p>The resulting sequence of strings (one for each supplied argument) is then reduced
to a single string by applying <code>fn:string-join#1</code> to the sequence.</p>
<p>The <code>fn:concat</code> function is specified to allow zero or more arguments, which
are concatenated together. This is the only function specified in this document that
allows a variable number of arguments. This capability is retained for compatibility
with <bibref
ref="xpath"/>. </p>
<p>This function is defined to be variadic. It defines a single parameter with the required type
<code>xs:anyAtomicType*</code>, but because the function is variadic,
the input sequence may be supplied using multiple arguments. In addition
the parameter is declared optional, so a call with no arguments is also permitted.</p>

<p>The result of the function is obtained by forming the sequence-concatenation of the supplied
argument values and applying the function <code>fn:string-join#0</code> to the result.</p>

<p>If XPath 1.0 compatibility mode is set to true in the static context of a
static function call to <code>fn:concat</code>, then each supplied argument
<code>$v</code> is first reduced to a single
string, the result of the expression <code>xs:string($v[1])</code>. This is special-case
processing for the <code>fn:concat</code> function, it is not something
that follows from the general rules for calling variadic functions. This reflects the fact that
<code>fn:concat</code> had custom behavior in XPath 1.0. This rule applies only to
static function calls.</p>

</fos:rules>
<fos:notes>
<p>As mentioned in <specref ref="string-types"
Expand All @@ -4191,6 +4202,9 @@ return normalize-unicode(concat($v1, $v2))</eg>
(Unicode codepoint <code>U+0308</code>) or <code>&amp;#x0308;</code>, will return:</p>
<p><code>"I plan to go to München in September"</code></p>
<p>This returned result is normalized in NFC.</p>
<p>Alternatives to the <code>fn:concat</code> function include the concatenation operator
<code>||</code> (for example <code>$x || '-' || $y</code>), and the use of string templates
(for example <code>`{$x}-{$y}`)</code>.</p>
</fos:notes>
<fos:examples>
<fos:example>
Expand Down
5 changes: 5 additions & 0 deletions specifications/xpath-functions-40/src/xpath-functions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1165,6 +1165,11 @@ This includes all the built-in datatypes defined in <bibref ref="xmlschema-2"/>.
repeated calls with the same explicit and implicit arguments <rfc2119>must</rfc2119> return
identical results.</p>

<p><termdef id="dt-variadic" term="variadic">Several functions defined in this specification
are defined as variadic. This means that in a static function call, several arguments
in the function call can be sequence-concatenated to supply the value of a single parameter
in the function definition.</termdef></p>

</div3>
</div2>
</div1>
Expand Down
9 changes: 9 additions & 0 deletions specifications/xquery-40/src/errors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1115,6 +1115,15 @@ It is a static error if the name of a feature in
are not compatible as defined in <xspecref spec="DM40" ref="schema-consistency"/>.</p>
</error>

<error spec="XQ" role="xquery" code="0150" class="ST" type="static">
<p> It is a <termref def="dt-static-error">static error</termref>
if any of the parameters in a variadic function declaration
is declared as optional: that is,
if a function declaration is annotated as
<code>%variadic</code> then none of its parameters may
contain a <nt def="ParamWithDefault">ParamWithDefault</nt>.</p>
</error>


</error-list>
</div1>
Loading

0 comments on commit ad2bdcb

Please sign in to comment.