VocabularysequencesInputsseq | a mutable sequence |
identity | an object |
quot | a quotation with stack effect ( ... prev elt -- ... next ) |
Outputsseq | a mutable sequence |
final | the final result |
Word descriptionCombines successive elements of the sequence using a binary operation, and outputs the original sequence of intermediate results, together with the final result.
The first element of the new sequence is
identity. Then, on the first iteration, the two inputs to the quotation are
identity, and the first element of the old sequence. On successive iterations, the first input is the result of the previous iteration, and the second input is the corresponding element of the old sequence.
When given the empty sequence, outputs the same empty sequence together with the
identity.
ErrorsThrows an error if the sequence is immutable, or the sequence cannot hold elements of the type output by
quot.
Side effectsModifies
seqExamplesUSING: math prettyprint sequences ;
{ 2 2 2 2 2 } 0 [ + ] accumulate! . .
{ 0 2 4 6 8 }
10
NotesMay be named
scan or
prefix sum in other languages.
See alsoaccumulate,
accumulate-as,
accumulate*,
accumulate*!,
accumulate*-asDefinition