From 38a5184fdf123d7a9afe7801f7f4d065868da5f3 Mon Sep 17 00:00:00 2001 From: Joe Groff Date: Mon, 31 Oct 2011 18:55:21 -0700 Subject: [PATCH] math.statistics: fix stack effect on collect-by --- basis/math/statistics/statistics-tests.factor | 11 ++++++++++- basis/math/statistics/statistics.factor | 4 ++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/basis/math/statistics/statistics-tests.factor b/basis/math/statistics/statistics-tests.factor index 0d3172f685..ec6cda05b1 100644 --- a/basis/math/statistics/statistics-tests.factor +++ b/basis/math/statistics/statistics-tests.factor @@ -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 diff --git a/basis/math/statistics/statistics.factor b/basis/math/statistics/statistics.factor index 46b24bc98b..54edff34a4 100644 --- a/basis/math/statistics/statistics.factor +++ b/basis/math/statistics/statistics.factor @@ -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 )