diff --git a/specifications/grammar-40/xpath-grammar.xml b/specifications/grammar-40/xpath-grammar.xml index 2f2abe7c9..46492d69c 100644 --- a/specifications/grammar-40/xpath-grammar.xml +++ b/specifications/grammar-40/xpath-grammar.xml @@ -1533,14 +1533,8 @@ VersionDecl ::= "xquery" (("encoding" StringLiteral) | ("version" StringLiteral - - - - - - - - + + @@ -1913,18 +1907,6 @@ VersionDecl ::= "xquery" (("encoding" StringLiteral) | ("version" StringLiteral * - - - - - - - - - - - - diff --git a/specifications/xquery-40/src/expressions.xml b/specifications/xquery-40/src/expressions.xml index bc9b3272a..45f12ae11 100644 --- a/specifications/xquery-40/src/expressions.xml +++ b/specifications/xquery-40/src/expressions.xml @@ -22115,6 +22115,12 @@ return string-join($chopped, '; ') Arrow Expressions + + An arrow operator may now be followed by any dynamic function + call; the dynamic function call no longer needs to start with a variable reference + or a parenthesized expression. + +

Arrow expressions apply a function to a value, using the value of the left-hand expression as the first argument to the function.

@@ -22162,30 +22168,35 @@ return string-join($chopped, '; ') =!> upper-case() => string-join(" ")]]> -

returns "THE. CAT. SAT. ON. THE. MAT.". The first arrow +

returns "THE. CAT. SAT. ON. THE. MAT.". The first arrow could be written either as => or =!> because the operand is a singleton; the next two arrows have to be =!> because the function is applied to each item in the tokenized sequence individually; the final arrow must be => because the string-join function applies to the sequence as a whole.

-

It may be useful to think of this as a map/reduce pipeline. The functions +

It may be useful to think of this as a map/reduce pipeline. The functions introduced by =!> are mapping operations; the function introduced by => is a reduce operation.

-

The following example introduces an inline function to the pipeline:

+

The following example introduces an inline function to the pipeline:

xs:double() =!> math:sqrt() =!> fn($a) { $a + 1 }() => sum()]]> -

This is equivalent to sum((1 to 5) ! (math:sqrt(xs:double(.)) + 1)).

+

This is equivalent to sum((1 to 5) ! (math:sqrt(xs:double(.)) + 1)).

-

The same effect can be achieved using a :

+

The same effect can be achieved using a :

- xs:double() =!> math:sqrt() =!> fn { . + 1 }() => sum()]]> +

It could also be expressed using the mapping operator !:

+ + sum()]]> +

Where the value of an expression is a map containing functions, simulating the behavior of objects in object-oriented languages, then the lookup arrow operator =?> - can be used to retrive a function from the map and to invoke the function with the map as its + can be used to retrieve a function from the map and to invoke the function with the map as its first argument. For example, if my:rectangle returns a map with entries width, height, expand, and area, then it becomes possible to write:

@@ -22193,7 +22204,8 @@ return string-join($chopped, '; ') expand(2) =?> area()]]> -

The ArgumentList may include PlaceHolders, +

The ArgumentList of the function call + may include PlaceHolders, though this is not especially useful. For example, the expression "$" => concat(?) is equivalent to concat("$", ?): its value is a function that prepends a supplied string with a $ symbol.

@@ -22215,6 +22227,13 @@ return string-join($chopped, '; ') operation.

+

The expression U => $V(X)(Y) satisfies the grammar, but its meaning + might not be obvious. It is interpreted as being equivalent to $V(X)(U, Y). + The same applies to the mapping arrow operator: U =!> $V(X)(Y) is + interpreted as for $u in $V return $V(X)($u, Y). This follows from + the way that the syntax of a DynamicFunctionCall + is defined.

+ @@ -22229,18 +22248,28 @@ return string-join($chopped, '; ') -

Given a UnaryExpr - U, an ArrowStaticFunction - F, and an ArgumentList - (A, B, C...), the expression U => F(A, B, C...) is equivalent to the - expression F(U, A, B, C...).

-

Given a UnaryExpr - U, an ArrowDynamicFunction - F, and an PositionalArgumentList - (A, B, C...), the expression U => F(A, B, C...) is equivalent to the - expression F(U, A, B, C...).

+ +

If the arrow is followed by a static FunctionCall:

+

Given a UnaryExpr + U and a FunctionCall + F(A, B, C...), + the expression U => F(A, B, C...) + is equivalent to the expression + F(U, A, B, C...).

+ +

If the arrow is followed by a DynamicFunctionCall:

+

Given a UnaryExpr + U, and a DynamicFunctionCall + E(A, B, C...), the expression + U => E(A, B, C...) is equivalent to the + expression E(U, A, B, C...).

+

Although the syntax of an arrow expression makes use of the grammatical productions + FunctionCall and DynamicFunctionCall, + these are not evaluated in the same way as a function call that appears as a + free-standing expression.

+ @@ -22255,29 +22284,30 @@ return string-join($chopped, '; ') -

+

The mapping arrow operator =!> applies a function to each item in a sequence. It is defined as follows:

- + + -

If the arrow is followed by an ArrowStaticFunction:

-

Given a UnaryExpr - U, an ArrowStaticFunction - F, and an ArgumentList - (A, B, C...), the expression U =!> F(A, B, C...) is equivalent to the - expression (for $u in U return F($u, A, B, C...)).

- -
+

If the arrow is followed by a static FunctionCall:

+

Given a UnaryExpr + U and a FunctionCall + F(A, B, C...), + the expression U =!> F(A, B, C...) + is equivalent to the expression + for $u in U return + F($u, A, B, C...).

-

If the arrow is followed by an ArrowDynamicFunction:

-

Given a UnaryExpr - U, an ArrowDynamicFunction - F, and an PositionalArgumentList - (A, B, C...), the expression U =!> F(A, B, C...) is equivalent to the - expression (for $u in U return F($u, A, B, C...)).

- -
+

If the arrow is followed by a DynamicFunctionCall:

+

Given a UnaryExpr + U, and a DynamicFunctionCall + E(A, B, C...), the expression + U => E(A, B, C...) is equivalent to the + expression for $u in U return E($u, A, B, C...).

+ +