Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env bash
- exec guile $0
- # !#
- (import (ice-9 rdelim)
- (ice-9 hash-table))
- (define (count-or-unicode>? a b)
- (or (> (car a) (car b))
- (and (= (car a) (car b))
- (string<? (cdr a) (cdr b)))))
- (define (count-words port)
- (define count (make-hash-table))
- (let loop ([next (read-delimited " \t\n" port)])
- (unless (eof-object? next)
- (let ((num (hash-ref count next 0)))
- (hash-set! count next (+ num 1))
- (loop (read-delimited " \t\n" port)))))
- (sort
- (hash-fold (lambda (key val prior) (cons (cons val key) prior)) '() count)
- count-or-unicode>?))
- (for-each
- (lambda (x) (format #t "~a\t~a\n" (cdr x) (car x)))
- (count-words (current-input-port)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement