From 411427d7d34fd0b4790a1beba1b3fbb54a0f2993 Mon Sep 17 00:00:00 2001
From: Michael Kay file:
scheme.
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 the complete (ordered) sequence of all 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):
+The result of the function is the value of the expression:
+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
.
See fn:fold-left
: errors are raised in the same situations.
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. -
-A practical implementation might be expected to evaluate the result + incrementally in a single pass of the input; the equivalent expression + given in the rules above is provided purely for formal specification + purposes.
+Each intermediate result is placed in a separate array. The number of arrays
+ in the result is the same as the number of items in $input
.
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
+ an call on fn:fold-left
with the same arguments, perhaps for
+ diagnostic purposes.
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 the complete (ordered) sequence of all 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):
+The result of the function is the value of the expression:
+ +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
.
See fn:fold-left
: errors are raised in the same situations.
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. -
-A practical implementation might be expected to evaluate the result + incrementally in a single right-to-left pass of the input; the equivalent expression + given in the rules above is provided purely for formal specification + purposes.
+Each intermediate result is placed in a separate array. The number of arrays
+ in the result is the same as the number of items in $input
.
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
+ an call on fn:fold-right
with the same arguments, perhaps for
+ diagnostic purposes.
The function is equivalent to the following implementation in XQuery:
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:
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)))))
.file:
scheme.
file:
scheme.
Produces the complete (ordered) sequence of all intermediate
- results of an evaluation of fn:fold-left
.
Produces a sequence containing intermediate results of an evaluation of fn:fold-left
.
The result of the function is the value of the expression:
-The function is equivalent to the following implementation in XQuery:
- +) as item()* { + array{$zero}, + if (exists($input)) { + scan-left( + tail($input), + $action($zero, head($input)), + $action + ) + } +};]]> + +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.
See fn:fold-left
: errors are raised in the same situations.
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
.
A practical implementation might be expected to evaluate the result - incrementally in a single pass of the input; the equivalent expression - given in the rules above is provided purely for formal specification - purposes.
-Each intermediate result is placed in a separate array. The number of arrays
- in the result is the same as the number of items in $input
.
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
- an call on fn:fold-left
with the same arguments, perhaps for
- diagnostic purposes.
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 intermediate
- results of an evaluation of fn:fold-right
.
Produces a sequence containing intermediate results of an evaluation of fn:fold-right
.
The result of the function is the value of the expression:
+The function is equivalent to the following implementation in XQuery:
-The result is a sequence of arrays representing intermediate results. The last array
+ holds the value of $zero
. Subsequent 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.
See fn:fold-left
: errors are raised in the same situations.
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
.
A practical implementation might be expected to evaluate the result - incrementally in a single right-to-left pass of the input; the equivalent expression - given in the rules above is provided purely for formal specification - purposes.
-Each intermediate result is placed in a separate array. The number of arrays
- in the result is the same as the number of items in $input
.
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
- an call on fn:fold-right
with the same arguments, perhaps for
- diagnostic purposes.
fn:fold-right
with the same arguments, perhaps for
+ diagnostic purposes. It can also be used to produce the running totals of
+ a computation.
Applies the function item $action
to every item from the sequence $input
+
Applies the function item $action
to every item from the sequence $input
in turn, returning the concatenation of the resulting sequences in order.
The result is a sequence of arrays representing intermediate results. The last array
- holds the value of $zero
. Subsequent arrays, one per item in $input
,
+ 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.
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
@@ -19503,7 +19516,7 @@ declare function fold-left(
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.
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 a sequence containing intermediate results of an evaluation of fn:fold-left
.
The function is equivalent to the following implementation in XQuery:
+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
@@ -31350,10 +31395,7 @@ declare function scan-left(
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.
The number of arrays
@@ -31400,7 +31442,7 @@ declare function scan-left(
Produces a sequence containing intermediate results of an evaluation of The function is equivalent to the following implementation in XQuery: In the case where the supplied fn:fold-right
.$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
,
@@ -31436,10 +31494,7 @@ declare function scan-right(
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.
The number of arrays