{"size": 1181, "ext": "rktl", "max_stars_repo_path": "pkgs/racket-benchmarks/tests/racket/benchmarks/shootout/typed/wordfreq.rktl", "max_stars_repo_name": "lkh01/racket", "max_stars_repo_stars_event_min_datetime": "2018-07-05T21:18:24.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-04T14:48:37.000Z", "max_issues_repo_path": "pkgs/racket-benchmarks/tests/racket/benchmarks/shootout/typed/wordfreq.rktl", "max_issues_repo_name": "lkh01/racket", "max_issues_repo_issues_event_min_datetime": "2017-05-10T07:33:20.000Z", "max_issues_repo_issues_event_max_datetime": "2018-07-19T15:49:46.000Z", "max_forks_repo_path": "pkgs/racket-benchmarks/tests/racket/benchmarks/shootout/typed/wordfreq.rktl", "max_forks_repo_name": "lkh01/racket", "max_forks_repo_forks_event_min_datetime": "2016-04-25T11:47:57.000Z", "max_forks_repo_forks_event_max_datetime": "2017-05-09T14:52:48.000Z"}
{"max_stars_count": 4, "max_issues_count": 9, "max_forks_count": 3, "avg_line_length": 32.8055555556, "max_line_length": 79, "alphanum_fraction": 0.5419136325}
; $Id: wordfreq-mzscheme.code,v 1.10 2006/06/21 15:05:34 bfulgham Exp $
;  http://shootout.alioth.debian.org/
;  wordfreq.mzscheme by Grzegorz Chrupaa
;  Updated and corrected by Brent Fulgham
;  Re-written by Matthew Flatt with some inspriation from the Python example
;  Converted to Typed Scheme by Vincent St-Amour

(require mzlib/list)

(: t (HashTable String Natural))
(define t (make-hash))

(: register-word! (Bytes -> Void))
(define (register-word! s)
  (let ([s (string-downcase (bytes->string/utf-8 s))])
    (hash-set! t s (add1 (hash-ref t s (lambda () 0))))))

(let ([in (current-input-port)])
  (let: loop : Void ()
    (let ([m (regexp-match #rx#"[a-zA-Z]+" in)])
      (when m
        (register-word! (assert (car m)))
        (loop)))))

(for-each display
          ((inst sort String String)
           (hash-map
            t
            (lambda: ((word : String) (count : Natural))
                     (let ((count (number->string count)))
                       (format"~a~a ~a\n"
                              (make-string (- 7 (string-length count)) #\space)
                              count
                              word))))
           string>?))
