add histogram word to assocs.lib

db4
Doug Coleman 2008-05-28 17:51:02 -05:00
parent 8f06c94ee8
commit 0f040470d7
1 changed files with 6 additions and 1 deletions

View File

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