Paste: cleaned up version

Author: slava
Mode: factor
Date: Tue, 9 Dec 2008 20:36:39
Plain Text |
USING: arrays assocs kernel io math math.parser
prettyprint sequences splitting sorting ;

IN: wp

: inc-at ( key assoc -- ) [ 1 ] 2dip at+ ; inline

: count-words ( string assoc -- assoc' )
    [ " " split harvest ] dip '[ _ inc-at ] each ;

: sort-assoc ( assoc -- seq )
   >alist sort-values reverse ;

: print-results ( seq -- )
   [ number>string "    " glue print ] assoc-each ;

H{ } clone
[ '[ _ count-words ] each-line ]
[ sort-assoc print-results ]
bi

New Annotation

Summary:
Author:
Mode:
Body: