math.statistics: fix stack effect on collect-by

db4
Joe Groff 2011-10-31 18:55:21 -07:00
parent 27ac4c60f4
commit 38a5184fdf
2 changed files with 12 additions and 3 deletions

View File

@ -1,4 +1,4 @@
USING: kernel math math.functions math.statistics tools.test ;
USING: assocs kernel math math.functions math.statistics sequences tools.test ;
IN: math.statistics.tests
[ 1 ] [ { 1 } mean ] unit-test
@ -53,3 +53,12 @@ IN: math.statistics.tests
] [
"aabbcc" histogram
] unit-test
{
V{ 0 3 6 9 }
V{ 1 4 7 }
V{ 2 5 8 }
} [
10 iota [ 3 mod ] collect-by
[ 0 swap at ] [ 1 swap at ] [ 2 swap at ] tri
] unit-test

View File

@ -84,10 +84,10 @@ PRIVATE>
: sorted-histogram ( seq -- alist )
histogram sort-values ;
: collect-pairs ( seq quot: ( x -- x' ) -- hashtable )
: collect-pairs ( seq quot: ( x -- v k ) -- hashtable )
[ push-at ] sequence>hashtable ; inline
: collect-by ( seq quot -- hashtable )
: collect-by ( seq quot: ( x -- x' ) -- hashtable )
[ dup ] prepose collect-pairs ; inline
: mode ( seq -- x )