]> gitweb.factorcode.org Git - factor.git/commitdiff
sequences: 'accumulate' now outputs a sequence of the same type as its input
authorSlava Pestov <slava@slava-pestovs-macbook-pro.local>
Thu, 15 Apr 2010 02:00:37 +0000 (19:00 -0700)
committerSlava Pestov <slava@slava-pestovs-macbook-pro.local>
Thu, 15 Apr 2010 04:51:00 +0000 (21:51 -0700)
core/sequences/sequences-docs.factor
core/sequences/sequences-tests.factor
core/sequences/sequences.factor

index 8d6ddf1be9900ad89d24747469b3c4b9a39dd30d..f7f774ad8615bc2f399884327be46e732beb4466 100644 (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
index 665e7a7ada07a6772f9efa1f7b9cb70e99034fbd..175ab252e13af9c1d62658e1b304c0d200d3458b 100644 (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
 
index 02c5d0ac72822e245f6b0d298c7ab201577435d8..d9c234e717981842d1b565da99d2c1acc5e67af3 100644 (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