Paste: count occurrences (please improve)
Author: | sconcrete |
Mode: | factor |
Date: | Fri, 23 Jan 2009 19:07:13 |
Plain Text |
: increment-val-for-key ( key assoc -- )
2dup
at*
[ 1 + ] [ drop 1 ] if
-rot
set-at ;
: count-occurrences ( str -- assoc )
V{ } dup
-rot
[ increment-val-for-key ] curry each ;
Author: | sconcrete |
Mode: | factor |
Date: | Fri, 23 Jan 2009 19:46:42 |
Plain Text |
: at++ ( key assoc -- )
1 -rot at+ ;
: count-char-frequency ( str -- hashtable )
H{ } tuck [ at++ ] curry each ;
Author: | Dan |
Mode: | factor |
Date: | Fri, 23 Jan 2009 19:51:01 |
Plain Text |
: frequency ( seq -- hashtable )
H{ } clone tuck '[ 1 swap _ at+ ] each ;
New Annotation