Handbook
Glossary
cum-count ( seq quot: ( elt -- ? ) -- seq' )
Statistics
ยป
Computing cumulative sequences
Prev:
cum-max ( seq -- seq' )
Vocabulary
math
.
statistics
Inputs
seq
a
sequence
quot
a
quotation
with stack effect
( elt -- ? )
Outputs
seq'
a
sequence
Word description
Returns the cumulative count of how many times
quot
returns true.
Examples
USING: math math.statistics prettyprint ; { 1 -1 2 -1 4 } [ 0 < ] cum-count .
{ 0 1 1 2 2 }
Definition
USING:
kernel
math
sequences
;
IN:
math.statistics
:
cum-count
( seq quot: ( elt -- ? ) -- seq' )
[
0
]
dip
[
[
1
+
]
when
]
compose
accumulate*
;
inline