From 9fdcaa4afe11a1ca718ca7d6bcb7d3ebddd9a636 Mon Sep 17 00:00:00 2001 From: Michael Kay Date: Mon, 28 Oct 2024 18:32:58 +0000 Subject: [PATCH] Drop variadic functions --- .../src/function-catalog.xml | 72 +++++++++++++++---- .../src/xpath-functions.xml | 14 ++-- specifications/xquery-40/src/errors.xml | 4 +- specifications/xquery-40/src/expressions.xml | 48 ++++++------- specifications/xquery-40/src/query-prolog.xml | 8 +-- specifications/xslt-40/src/xslt.xml | 8 +-- 6 files changed, 100 insertions(+), 54 deletions(-) diff --git a/specifications/xpath-functions-40/src/function-catalog.xml b/specifications/xpath-functions-40/src/function-catalog.xml index db349864c..23e531460 100644 --- a/specifications/xpath-functions-40/src/function-catalog.xml +++ b/specifications/xpath-functions-40/src/function-catalog.xml @@ -4747,18 +4747,50 @@ translate(value := '٢٠٢٣', replace := '٠١٢٣٤٥٦٧٨٩', with := '01234

Returns the concatenation of the arguments, treated as sequences of strings.

-

This function is defined to be variadic. It defines a single parameter with the required type - xs:anyAtomicType*, 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.

+

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):

+ + +

concat() returns a zero-length string, "".

+

concat("a") returns "a".

+

concat("a", "b") returns "ab".

+

concat("a", "b", "c") returns "abc".

+

concat("a", "b", "c", "d") returns "abcd".

+

and so on.

+
+ +

It is equally possible to supply a single argument containing a sequence of strings:

+ + +

concat(()) returns a zero-length string, "".

+

concat(("a")) returns "a".

+

concat(("a", "b")) returns "ab".

+

concat(("a", "b", "c")) returns "abc".

+

concat(("a", "b", "c", "d")) returns "abcd".

+

and so on.

+
+ +

More generally, any argument can be a sequence of strings:

+ + +

concat(("a", "b"), "c") returns "abc".

+

concat(("a", "b"), (), ("c", "d")) returns "abcd".

+
+ +

A static call on the concat function must use positional arguments, + it cannot use keywords.

+ +

Each of the parameters has the required type + xs:anyAtomicType*. 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 + sequence concatenation) + into a single sequence, and each item in the combined sequence + is converted to a string using the fn:string function. The strings are then concatenated + with no separator.

+ -

The coercion rules ensure that each supplied $values argument is first converted to - a sequence of atomic items by applying atomization.

-

The result of the function is then obtained by forming the - sequence concatenation of these atomized - values and applying the function fn:string-join#1 to the result. The call - on fn:string-join has the effect of casting each atomic item in the sequence - to an xs:string.

If XPath 1.0 compatibility mode is set to true in the static context of a static function call to fn:concat, then each supplied argument @@ -4768,6 +4800,14 @@ translate(value := '٢٠٢٣', replace := '٠١٢٣٤٥٦٧٨٩', with := '01234 that follows from the general rules for calling variadic functions. This reflects the fact that fn:concat had custom behavior in XPath 1.0. This rule applies only to static function calls.

+ +

A named function reference can be used to create a function item with any arity: for example + concat#3 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 concat('[', ?, ']') returns a function item that takes a single + argument and wraps the string value of this argument in square brackets. Similarly, + concat(?, '-', ?) returns a function item of arity two; it returns the string values of + the two arguments separated by a hyphen.

@@ -4796,8 +4836,8 @@ return normalize-unicode(concat($v1, $v2))

"I plan to go to München in September"

This returned result is normalized in NFC.

Alternatives to the fn:concat function include the concatenation operator - || (for example $x || '-' || $y), and the use of string templates - (for example `{$x}-{$y}`).

+ || (for example $x || '-' || $y), the use of string templates + (for example `{$x}-{$y}`), and the fn:string-join function.

@@ -4806,6 +4846,12 @@ return normalize-unicode(concat($v1, $v2)) "ungrateful" + + + concat(('un', 'grateful')) + "ungrateful" + + concat( diff --git a/specifications/xpath-functions-40/src/xpath-functions.xml b/specifications/xpath-functions-40/src/xpath-functions.xml index 1f5fc7b7a..7be1b0826 100644 --- a/specifications/xpath-functions-40/src/xpath-functions.xml +++ b/specifications/xpath-functions-40/src/xpath-functions.xml @@ -583,8 +583,8 @@ for transition to Proposed Recommendation.

'>

The name of the parameter (which in 4.0 is significant because it can be used as a keyword in a function call)

The static type of the parameter (in italics)

-

If this is the last parameter of a function, - an ellipsis (...)

+

If the parameter is optional, then an expression giving the default value (preceded by the symbol :=).

The default value expression is evaluated using the static and @@ -601,9 +601,9 @@ for transition to Proposed Recommendation.

'> type or derived from the static type. All parameter types and return types are specified using the SequenceType notation defined in .

-

If a function is , it has a variable number of arguments + @@ -1315,9 +1315,9 @@ This includes all the built-in datatypes defined in . repeated calls with the same explicit and implicit arguments must return identical results.

-

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.

+

The function fn:concat + is defined to be variadic: it accepts any number of arguments. No other function + has this property.

diff --git a/specifications/xquery-40/src/errors.xml b/specifications/xquery-40/src/errors.xml index d2fcd767e..038a1e547 100644 --- a/specifications/xquery-40/src/errors.xml +++ b/specifications/xquery-40/src/errors.xml @@ -1117,14 +1117,14 @@ It is a static error if the name of a feature in are not compatible as defined in .

- +

It is a static error diff --git a/specifications/xquery-40/src/expressions.xml b/specifications/xquery-40/src/expressions.xml index 458495f63..4532a196d 100644 --- a/specifications/xquery-40/src/expressions.xml +++ b/specifications/xquery-40/src/expressions.xml @@ -898,7 +898,7 @@ constructor, as described in M required parameters and N optional parameters, then its arity range is from M to M+N inclusive.

-

A may +

The static context may contain several function definitions with the same name, but the arity ranges of two such function definitions must not @@ -922,7 +922,7 @@ constructor, as described in

It is not acceptable for A to have one required parameter while B has three optional parameters.

-

It is not possible for both A and B to be .

+

Implementations must ensure that no two function definitions @@ -9185,11 +9185,11 @@ At evaluation time, the value of a variable reference is the value to which the Static Function Calls - +

The for an expression includes a set of . Every @@ -9420,11 +9420,11 @@ At evaluation time, the value of a variable reference is the value to which the

If there are N positional arguments in the function call FC, - and FD is not , then + then the corresponding argument expressions are matched pairwise to the first N parameters in the declaration. For this purpose the required parameters and optional parameters in FD are concatenated into a single list, in order.

-

If there are N positional arguments and no keyword arguments +

Any keyword arguments in FC are then matched to parameters (whether required or optional) in FD by comparing the keyword used in FC with the paramater name declared in FD. @@ -9488,9 +9488,9 @@ At evaluation time, the value of a variable reference is the value to which the

This applies both to explicitly supplied arguments, and to values obtained by evaluating default value expressions. In both cases a type error will be raised if the value (after coercion) does not match the required type.

-

In the case of a function, the coercion rules are applied + @@ -9982,7 +9982,7 @@ return $vat(doc('wares.xml')/shop/article) arguments.

-

If FD is , and + -

If FD is , and + -

In other cases, the parameters of FD are classified into three categories:

+

The parameters of FD are classified into three categories:

Parameters that map to a placeholder, referred to as placeholder parameters.

Parameters for which an explicit value is given in the function call (either @@ -10395,22 +10395,22 @@ return $a("A")]]>

parameter names: The first A parameter names of FD, where A is the required arity.

-

In the case where FD is and +

signature: Formed from the required types of the first A parameters of FD, and the function result type of FD.

-

In the case where FD is and +

body: The body of FD.

@@ -10461,10 +10461,10 @@ return $a("A")]]>

Function items, as values in the data model, have a fixed arity, and - a dynamic function call always supplies the arguments positionally. Although the base function + a dynamic function call always supplies the arguments positionally. In effect, the result of evaluating my:func#3 is the + same as the result of evaluating the inline function expression fn($x, $y, $z) { my:func($x, $y, $z) }, except that the returned function has a name (it retains the name my:func).

@@ -10743,7 +10743,7 @@ return $incrementors[2](4)]]> - + diff --git a/specifications/xquery-40/src/query-prolog.xml b/specifications/xquery-40/src/query-prolog.xml index 02e8d5e14..6671cedb8 100644 --- a/specifications/xquery-40/src/query-prolog.xml +++ b/specifications/xquery-40/src/query-prolog.xml @@ -1808,10 +1808,10 @@ local:summary(doc("acme_corp.xml")//employee[location = "Denver"]) Function Annotations - + The values true() and false() are allowed in function annotations, and negated numeric literals are also allowed. @@ -1835,12 +1835,12 @@ local:summary(doc("acme_corp.xml")//employee[location = "Denver"]) %private and a %public annotation, more than one %private annotation, or more than one %public annotation.

-

The function annotation %variadic declares the corresponding +

An implementation can define annotations, in its own namespace, to support functionality beyond the scope of this specification. For instance, an implementation that supports external diff --git a/specifications/xslt-40/src/xslt.xml b/specifications/xslt-40/src/xslt.xml index e6701e9e7..55f67fc05 100644 --- a/specifications/xslt-40/src/xslt.xml +++ b/specifications/xslt-40/src/xslt.xml @@ -19070,8 +19070,8 @@ and version="1.0" otherwise.

The list of parameters must contain zero or more required parameters, followed by zero or more optional parameters. A parameter is optional if it has the attribute required="no"; otherwise, it is required.

-

Special rules apply if the function is declared with variadic="yes": see - .

+

The default value for an optional parameter can be defined using the select attribute or the contained of the xsl:param element. These must be absent @@ -19238,7 +19238,7 @@ and version="1.0" otherwise.

- + Visibility and Overriding of Functions