sequences: 'accumulate' now outputs a sequence of the same type as its input

release
Slava Pestov 2010-04-14 19:00:37 -07:00
parent c595c4a151
commit f40b313be5
3 changed files with 5 additions and 2 deletions

View File

@ -286,7 +286,7 @@ $nl
HELP: accumulate
{ $values { "seq" sequence } { "identity" object } { "quot" { $quotation "( ... prev elt -- ... next )" } } { "final" "the final result" } { "newseq" "a new array" } }
{ $description "Combines successive elements of the sequence using a binary operation, and outputs an array of intermediate results, together with the final result."
{ $description "Combines successive elements of the sequence using a binary operation, and outputs a sequence of intermediate results, together with the final result."
$nl
"The first element of the new sequence is " { $snippet "identity" } ". Then, on the first iteration, the two inputs to the quotation are " { $snippet "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."
$nl

View File

@ -24,6 +24,9 @@ IN: sequences.tests
[ 5040 { 1 1 2 6 24 120 720 } ]
[ { 1 2 3 4 5 6 7 } 1 [ * ] accumulate ] unit-test
[ 64 B{ 1 2 4 16 } ]
[ B{ 2 2 4 4 } 1 [ * ] accumulate ] unit-test
[ 5040 { 1 1 2 6 24 120 720 } ]
[ { 1 2 3 4 5 6 7 } 1 [ * ] accumulate! ] unit-test

View File

@ -436,7 +436,7 @@ PRIVATE>
[ (accumulate) ] dip map-as ; inline
: accumulate ( ... seq identity quot: ( ... prev elt -- ... next ) -- ... final newseq )
{ } accumulate-as ; inline
pick accumulate-as ; inline
: accumulate! ( ... seq identity quot: ( ... prev elt -- ... next ) -- ... final seq )
(accumulate) map! ; inline