1:":"; exec mzscheme -r $0 "$@"
2:
3:(require (lib "vector-lib.ss" "srfi" "43"))
4:(require (lib "string.ss" "srfi" "13"))
5:
6:
7:; global word storage
8:(define words (make-hash-table 'equal))
9:(define tokencount 0)
10:
11:
12:(define load-file
13: (lambda (fname)
14: (printf "Loading file: ~a\n" fname)
15: (call-with-input-file fname
16: (lambda (p)
17: (read-string (file-size fname) p)))))
18:
19:
20:(define count-words
21: (lambda (wordlist)
22: (set! tokencount (+ tokencount (length wordlist)))
23: (for-each (lambda (word)
24: (let ([value (hash-table-get words word 0)])
25: (hash-table-put! words word (+ value 1))))
26: wordlist)))
27:
28:
29:;;; main steps
30:(begin
31: (vector-for-each (lambda (i fname)
32: (count-words (string-tokenize (load-file fname))))
33: argv)
34: (printf "Number of tokens: ~a\n" tokencount)
35: (printf "Number of types: ~a\n" (hash-table-count words)))