]> gitweb.factorcode.org Git - factor.git/commitdiff
add histogram word to assocs.lib
authorDoug Coleman <doug.coleman@gmail.com>
Wed, 28 May 2008 22:51:02 +0000 (17:51 -0500)
committerDoug Coleman <doug.coleman@gmail.com>
Wed, 28 May 2008 22:51:02 +0000 (17:51 -0500)
extra/assocs/lib/lib.factor

index 7c274edb2e548c5d0b37cf9b0077e033fe5aae23..c3e487a9fce6c598e9680b36557a66eca482ea41 100755 (executable)
@@ -1,5 +1,5 @@
 USING: arrays assocs kernel vectors sequences namespaces
-random math.parser ;
+random math.parser math fry ;
 IN: assocs.lib
 
 : ref-at ( table key -- value ) swap at ;
@@ -40,3 +40,8 @@ IN: assocs.lib
 
 : set-at-unique ( value assoc -- key )
     dup generate-key [ swap set-at ] keep ;
+
+: histogram ( assoc quot -- assoc' )
+    H{ } clone [
+        swap [ change-at ] 2curry assoc-each
+    ] keep ;