accumulate now returns the final result
parent
72efe34950
commit
e1abcf43b4
|
|
@ -1,7 +1,6 @@
|
|||
+ 0.84:
|
||||
|
||||
- update docs for declared effects
|
||||
- better doc for accumulate, link from tree
|
||||
- RT_WORD should refer to XTs not word objects.
|
||||
- better listener multi-line expression handling
|
||||
- history doesn't work in a good way if you ^K the input
|
||||
|
|
|
|||
|
|
@ -66,6 +66,7 @@ ARTICLE: "sequences-iteration" "Iteration and collection"
|
|||
"Iteration combinators:"
|
||||
{ $subsection each }
|
||||
{ $subsection reduce }
|
||||
{ $subsection accumulate }
|
||||
{ $subsection interleave }
|
||||
{ $subsection 2each }
|
||||
{ $subsection 2reduce }
|
||||
|
|
|
|||
|
|
@ -50,8 +50,8 @@ IN: sequences
|
|||
: map-with ( obj list quot -- newseq )
|
||||
swap [ with rot ] map 2nip ; inline
|
||||
|
||||
: accumulate ( seq identity quot -- newseq )
|
||||
rot [ pick >r swap call r> ] map-with nip ; inline
|
||||
: accumulate ( seq identity quot -- final newseq )
|
||||
rot [ pick >r swap call r> ] map-with ; inline
|
||||
|
||||
: change-nth ( i seq quot -- )
|
||||
-rot [ nth swap call ] 2keep set-nth ; inline
|
||||
|
|
|
|||
|
|
@ -21,10 +21,10 @@ HELP: reduce
|
|||
} ;
|
||||
|
||||
HELP: accumulate
|
||||
{ $values { "seq" "a sequence" } { "quot" "a quotation with stack effect " { $snippet "( prev elt -- next )" } } }
|
||||
{ $description "Combines successive elements of the sequence using a binary operation, and outputs a sequence of intermediate results. On the first iteration, the two inputs to the quotation are " { $snippet "identity" } ", and the first element of the sequence. On successive iterations, the first input is the result of the previous iteration, and the second input is the corresponding element of the sequence." }
|
||||
{ $values { "seq" "a sequence" } { "quot" "a quotation with stack effect " { $snippet "( prev elt -- next )" } } { "final" "the final result" } { "newseq" "a new sequence" } }
|
||||
{ $description "Combines successive elements of the sequence using a binary operation, and outputs a sequence of intermediate results together with the final result. On the first iteration, the two inputs to the quotation are " { $snippet "identity" } ", and the first element of the sequence. On successive iterations, the first input is the result of the previous iteration, and the second input is the corresponding element of the sequence. Given the empty sequence, outputs a one-element sequence consisting of " { $snippet "identity" } "." }
|
||||
{ $examples
|
||||
{ $example "{ 2 2 2 2 2 } 0 [ + ] accumulate ." "{ 0 2 4 6 8 }" }
|
||||
{ $example "{ 2 2 2 2 2 } 0 [ + ] accumulate . ." "{ 0 2 4 6 8 } 10" }
|
||||
} ;
|
||||
|
||||
HELP: map
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ kernel-internals math namespaces sequences words ;
|
|||
|
||||
: parameter-sizes ( types -- offsets )
|
||||
#! Compute stack frame locations.
|
||||
0 [ parameter-size + ] accumulate ;
|
||||
0 [ parameter-size + ] accumulate nip ;
|
||||
|
||||
: stack-space ( parameters -- n )
|
||||
0 [ parameter-size + ] reduce ;
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ sequences-internals strings test vectors ;
|
|||
|
||||
[ 5040 ] [ [ 1 2 3 4 5 6 7 ] 1 [ * ] reduce ] unit-test
|
||||
|
||||
[ [ 1 1 2 6 24 120 720 ] ]
|
||||
[ 5040 [ 1 1 2 6 24 120 720 ] ]
|
||||
[ [ 1 2 3 4 5 6 7 ] 1 [ * ] accumulate ] unit-test
|
||||
|
||||
[ -1 f ] [ [ ] [ ] find ] unit-test
|
||||
|
|
|
|||
|
|
@ -53,7 +53,7 @@ M: grid pref-dim*
|
|||
[ swap [ swap (pair-up) ] map-with ] map-with ;
|
||||
|
||||
: grid-positions ( dims -- locs )
|
||||
gap [ v+ gap v+ ] accumulate ;
|
||||
gap [ v+ gap v+ ] accumulate nip ;
|
||||
|
||||
: position-grid ( horiz vert -- )
|
||||
[ grid-positions ] 2apply
|
||||
|
|
|
|||
|
|
@ -102,7 +102,7 @@ TUPLE: pack align fill gap ;
|
|||
2dup packed-dim-2 swap orient ;
|
||||
|
||||
: gap-locs ( gap sizes -- seq )
|
||||
{ 0 0 } [ v+ over v+ ] accumulate nip ;
|
||||
{ 0 0 } [ v+ over v+ ] accumulate 2nip ;
|
||||
|
||||
: aligned-locs ( gadget sizes -- seq )
|
||||
[ >r dup pack-align swap rect-dim r> v- n*v ] map-with ;
|
||||
|
|
|
|||
|
|
@ -76,7 +76,7 @@ M: editor model-changed
|
|||
: run-char-widths ( str editor -- wlist )
|
||||
#! List of x co-ordinates of each character.
|
||||
editor-font* swap >array [ char-width ] map-with
|
||||
dup 0 [ + ] accumulate swap 2 v/n v+ ;
|
||||
dup 0 [ + ] accumulate nip swap 2 v/n v+ ;
|
||||
|
||||
: x>offset ( x line# editor -- col# )
|
||||
[ editor-line ] keep
|
||||
|
|
|
|||
Loading…
Reference in New Issue