Skip to content

Commit

Permalink
Drop variadic functions
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelhkay committed Oct 29, 2024
1 parent c58b5b8 commit 9fdcaa4
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 54 deletions.
72 changes: 59 additions & 13 deletions specifications/xpath-functions-40/src/function-catalog.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4747,18 +4747,50 @@ translate(value := '٢٠٢٣', replace := '٠١٢٣٤٥٦٧٨٩', with := '01234
<p>Returns the concatenation of the arguments, treated as sequences of strings.</p>
</fos:summary>
<fos:rules>
<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>Unlike all other functions, this function is defined to be variadic, as indicated by the
ellipsis in the function signature.
Conceptually, there is an infinite set of functions with different numbers of arguments (minimum arity zero,
maximum arity unbounded):</p>

<ulist>
<item><p><code>concat()</code> returns a zero-length string, <code>""</code>.</p></item>
<item><p><code>concat("a")</code> returns <code>"a"</code>.</p></item>
<item><p><code>concat("a", "b")</code> returns <code>"ab"</code>.</p></item>
<item><p><code>concat("a", "b", "c")</code> returns <code>"abc"</code>.</p></item>
<item><p><code>concat("a", "b", "c", "d")</code> returns <code>"abcd"</code>.</p></item>
<item><p>and so on.</p></item>
</ulist>

<p>It is equally possible to supply a single argument containing a sequence of strings:</p>

<ulist>
<item><p><code>concat(())</code> returns a zero-length string, <code>""</code>.</p></item>
<item><p><code>concat(("a"))</code> returns <code>"a"</code>.</p></item>
<item><p><code>concat(("a", "b"))</code> returns <code>"ab"</code>.</p></item>
<item><p><code>concat(("a", "b", "c"))</code> returns <code>"abc"</code>.</p></item>
<item><p><code>concat(("a", "b", "c", "d"))</code> returns <code>"abcd"</code>.</p></item>
<item><p>and so on.</p></item>
</ulist>

<p>More generally, any argument can be a sequence of strings:</p>

<ulist>
<item><p><code>concat(("a", "b"), "c")</code> returns <code>"abc"</code>.</p></item>
<item><p><code>concat(("a", "b"), (), ("c", "d"))</code> returns <code>"abcd"</code>.</p></item>
</ulist>

<p>A static call on the <code>concat</code> function must use positional arguments,
it cannot use keywords.</p>

<p>Each of the parameters has the required type
<code>xs:anyAtomicType*</code>. The coercion rules ensure that each supplied argument is first converted to
a sequence of atomic items by applying atomization. These sequences are then combined (by
<xtermref spec="XP40" ref="dt-sequence-concatenation">sequence concatenation</xtermref>)
into a single sequence, and each item in the combined sequence
is converted to a string using the <code>fn:string</code> function. The strings are then concatenated
with no separator.</p>


<p>The coercion rules ensure that each supplied <code>$values</code> argument is first converted to
a sequence of atomic items by applying atomization.</p>
<p>The result of the function is then obtained by forming the
<xtermref spec="XP40" ref="dt-sequence-concatenation">sequence concatenation</xtermref> of these atomized
values and applying the function <code>fn:string-join#1</code> to the result. The call
on <code>fn:string-join</code> has the effect of casting each atomic item in the sequence
to an <code>xs:string</code>.</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
Expand All @@ -4768,6 +4800,14 @@ translate(value := '٢٠٢٣', replace := '٠١٢٣٤٥٦٧٨٩', with := '01234
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>

<p>A named function reference can be used to create a function item with any arity: for example
<code>concat#3</code> returns a function item that takes three arguments, which it concatenates.
Similarly partial function application can be used to construct a function that concatenates fixed and
variable values: for example <code>concat('[', ?, ']')</code> returns a function item that takes a single
argument and wraps the string value of this argument in square brackets. Similarly,
<code>concat(?, '-', ?)</code> returns a function item of arity two; it returns the string values of
the two arguments separated by a hyphen.</p>

</fos:rules>
<fos:notes>
Expand Down Expand Up @@ -4796,8 +4836,8 @@ return normalize-unicode(concat($v1, $v2))</eg>
<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>
<code>||</code> (for example <code>$x || '-' || $y</code>), the use of string templates
(for example <code>`{$x}-{$y}`)</code>, and the <code>fn:string-join</code> function.</p>
</fos:notes>
<fos:examples>
<fos:example>
Expand All @@ -4806,6 +4846,12 @@ return normalize-unicode(concat($v1, $v2))</eg>
<fos:result>"ungrateful"</fos:result>
</fos:test>
</fos:example>
<fos:example>
<fos:test>
<fos:expression>concat(('un', 'grateful'))</fos:expression>
<fos:result>"ungrateful"</fos:result>
</fos:test>
</fos:example>
<fos:example>
<fos:test>
<fos:expression><eg>concat(
Expand Down
14 changes: 7 additions & 7 deletions specifications/xpath-functions-40/src/xpath-functions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -583,8 +583,8 @@ for transition to Proposed Recommendation. </p>'>
<item><p>The name of the parameter (which in 4.0 is significant because it can be used
as a keyword in a function call)</p></item>
<item><p>The static type of the parameter (in italics)</p></item>
<item><p>If this is the last parameter of a <termref def="dt-variadic"/> function,
an ellipsis (<code>...</code>)</p></item>
<!--<item><p>If this is the last parameter of a <termref def="dt-variadic"/> function,
an ellipsis (<code>...</code>)</p></item>-->
<item><p>If the parameter is optional, then an expression giving the default value
(preceded by the symbol <code>:=</code>).</p>
<p diff="add" at="2023-12-04">The default value expression is evaluated using the static and
Expand All @@ -601,9 +601,9 @@ for transition to Proposed Recommendation. </p>'>
type or derived from the static type. All parameter types and return types are
specified using the SequenceType notation defined in <xspecref spec="XP31" ref="id-sequencetype-syntax"/>.</p>

<p>If a function is <termref def="dt-variadic"/>, it has a variable number of arguments
<!--<p>If a function is <termref def="dt-variadic"/>, it has a variable number of arguments
(zero or more). More strictly, there is an infinite set of functions having the same name
and different arities.</p>
and different arities.</p>-->
</div3>

<div3 id="id-function-signatures-rules">
Expand Down Expand Up @@ -1315,9 +1315,9 @@ 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">If a variadic function is called,
several arguments in the function call are sequence-concatenated to supply the
value of a single parameter in the function definition.</termdef></p>
<p><termdef id="dt-variadic" term="variadic">The function <code>fn:concat</code>
is defined to be variadic: it accepts any number of arguments. No other function
has this property.</termdef></p>
</div3>
</div2>
</div1>
Expand Down
4 changes: 2 additions & 2 deletions specifications/xquery-40/src/errors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1117,14 +1117,14 @@ 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">
<!--<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>-->

<error spec="XQ" role="xquery" code="0151" class="ST" type="static">
<p> It is a <termref def="dt-static-error">static error</termref>
Expand Down
Loading

0 comments on commit 9fdcaa4

Please sign in to comment.