diff --git a/specifications/xpath-functions-40/src/function-catalog.xml b/specifications/xpath-functions-40/src/function-catalog.xml
index 2f0750fdc..ef8c07bfe 100644
--- a/specifications/xpath-functions-40/src/function-catalog.xml
+++ b/specifications/xpath-functions-40/src/function-catalog.xml
@@ -19236,7 +19236,7 @@ return map:keys($ann) || ': ' || string-join(map:values($ann), ', ')
Applies the function item Applies the function item $action
to every item from the sequence $input
+ $action
to every item from the sequence $input
in turn, returning the concatenation of the resulting sequences in order.
The function is equivalent to the following implementation in XQuery:
+When the supplied $action
has an arity of two or less,
+ the function is equivalent to the following implementation in XQuery:
The case where $action
has an arity of three can be handled by first building a sequence
+ of (position, item) pairs, and then calling the arity-2 function on this sequence:
As a consequence of the function signature and the function calling rules, a type error
- occurs if the supplied function $action
cannot be applied to two arguments, where
- the first argument is either the value of $zero
or the result of a previous
- application of $action
, and the second
- is any single item from the sequence $input
.
$action
cannot be applied to the supplied arguments.
This operation is often referred to in the functional programming literature as @@ -19424,8 +19425,7 @@ declare function fold-left( value (such as zero in the case of addition, one in the case of multiplication, or a zero-length string in the case of string concatenation) that causes the function to return the value of the other argument unchanged.
-The value of the third argument of $action
corresponds to the position
- of the item in the input sequence. It is initally set to 1
.
((((0+1)+2)+3)+4)+5)
.The function is equivalent to the following implementation in XQuery:
+When the supplied $action
has an arity of two or less,
+ the function is equivalent to the following implementation in XQuery:
The case where $action
has an arity of three can be handled by first building a sequence
+ of (position, item) pairs, and then calling the arity-2 function on this sequence:
As a consequence of the function signature and the function calling rules, a type error
- occurs if the supplied function $action
cannot be applied to two arguments, where
- the first argument is any item in the sequence $input
, and the second is either
- the value of $zero
or the result of a previous application of
- $action
.
$action
cannot be applied to the supplied arguments.
In cases where the function performs an associative operation on its two arguments (such
as addition or multiplication), fn:fold-right
produces the same result as
fn:fold-left
.
The value of the third argument of $action
corresponds to the position
- of the item in the input sequence. Thus, in contrast to fn:fold-left
,
- it is initally set to the number of items in the input sequence.
(0+(1+(2+(3+(4+5)))))
.The effect of the function is equivalent to the expression:
-The function is equivalent to the following expression:
+The function is equivalent to the following expression, which converts the array to a sequence and then
+ invokes fn:fold-left
:
The function is equivalent to the following expression:
+The function is equivalent to the following expression, which converts the array to a sequence and then
+ invokes fn:fold-right
:
file:
scheme.
Produces the complete (ordered) sequence of all partial results from every new value - the accumulator is assigned to during the evaluation of fn:fold-left.
+Produces a sequence containing intermediate results of an evaluation of fn:fold-left
.
The function is equivalent to the following implementation in XPath (return clause added in comments for completeness):
+In the case where the supplied $action
has an arity of two or less,
+ the function is equivalent to the following implementation in XQuery:
The case where $action
has an arity of three can be handled by first building a sequence
+ of (position, item) pairs, and then calling the arity-2 function on this sequence:
The result is a sequence of arrays representing intermediate results. The first array
+ holds the value of $zero
. Subsequent arrays, one per item in $input
,
+ represent the result of applying fn:fold-left
(with the same values for
+ $zero
and $action
) to the subsequence of $input
+ ending at that item.
As a consequence of the function signature and the function calling rules, a type error
- occurs if the supplied function $action
cannot be applied to two arguments, where
- the first argument is either the value of $zero
or the result of a previous
- application of $action
, and the second
- is any single item from the sequence $input
.
$action
cannot be applied to the supplied arguments.
Note that each intermediate result is placed in a separate singleton array. - This is necessary because we cannot represent a sequence of results, some or all of which are - a sequence - that is "sequence of sequences" as just a single sequence. -
-The number of arrays
+ in the result is the same as the number of items in $input
plus one.
The fact that the function has the same signature as fn:fold-left
+ means that this function can conveniently be used to study the behavior of
+ a call on fn:fold-left
with the same arguments, perhaps for
+ diagnostic purposes. It can also be used to produce the running totals of
+ a computation.
Produce the intermediate results of mapping each number in a sequence to its doubled value. - This example shows the necessity to place each intermediate result (sequence) into a singleton array - otherwise - the sequence of sequences (intermediate results) would not be possible to express as a single sequence - without losing completely the intermediate results.
Produce the factorials of all numbers from 0 to 5
Produces the complete (ordered) sequence of all partial results from every new value - the accumulator is assigned to during the evaluation of fn:fold-right.
+Produces a sequence containing intermediate results of an evaluation of fn:fold-right
.
The function is equivalent to the following implementation in XPath (return clause in comments added for completeness):
+In the case where the supplied $action
has an arity of two or less,
+ the function is equivalent to the following implementation in XQuery:
The case where $action
has an arity of three can be handled by first building a sequence
+ of (position, item) pairs, and then calling the arity-2 function on this sequence:
The result is a sequence of arrays representing intermediate results. The last array
+ holds the value of $zero
. Previous arrays, one per item in $input
,
+ represent the result of applying fn:fold-right
(with the same values for
+ $zero
and $action
) to the subsequence of $input
+ starting at that item.
As a consequence of the function signature and the function calling rules, a type error
- occurs if the supplied function $action
cannot be applied to two arguments, where
- the first argument is any item in the sequence $input
, and the second is either
- the value of $zero
or the result of a previous application of
- $action
.
$action
cannot be applied to the supplied arguments.
Note that each intermediate result is placed in a separate singleton array. - This is necessary because we cannot represent a sequence of results, some or all of which are - a sequence - that is "sequence of sequences" as just a single sequence. -
-The number of arrays
+ in the result is the same as the number of items in $input
plus one.
The fact that the function has the same signature as fn:fold-right
+ means that this function can conveniently be used to study the behavior of
+ a call on fn:fold-right
with the same arguments, perhaps for
+ diagnostic purposes. It can also be used to produce the running totals of
+ a computation.