]> gitweb.factorcode.org Git - factor.git/blobdiff - basis/math/statistics/statistics.factor
math.statistics: refactor histogram and histogram-by to use
[factor.git] / basis / math / statistics / statistics.factor
index 8be9dae79b86c1e74d0d85c76f583297d06f1e78..e9a61a9628d2ab516ac3e1db1c240f83a4a3ce18 100644 (file)
@@ -251,11 +251,14 @@ PRIVATE>
 : trimean ( seq -- x )
     quartile first3 [ 2 * ] dip + + 4 / ;
 
+: histogram-by! ( assoc seq quot: ( x -- bin ) -- hashtable )
+    rot [ '[ @ _ inc-at ] each ] keep ; inline
+
 : histogram! ( hashtable seq -- hashtable )
-    over '[ _ inc-at ] each ;
+    [ ] histogram-by! ; inline
 
 : histogram-by ( seq quot: ( x -- bin ) -- hashtable )
-    H{ } clone [ '[ @ _ inc-at ] each ] keep ; inline
+    [ H{ } clone ] 2dip histogram-by! ; inline
 
 : histogram ( seq -- hashtable )
     [ ] histogram-by ;