You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
22 lines
756 B
22 lines
756 B
(define-module (count-words) |
|
#:use-module (bible-tools) |
|
#:use-module (srfi srfi-1) |
|
#:use-module (srfi srfi-26) |
|
#:export (count-words)) |
|
|
|
(define (split/stuff str) |
|
(define (split-curry char) (cut string-split <> char)) |
|
(let ((splits (map split-curry '(#\, #\: #\. #\! #\? #\; #\< #\>)))) |
|
(clean-strings (fold mapcan (string-split str #\space) splits)))) |
|
|
|
(define (count verse result) |
|
(fold (lambda (word res) |
|
(let ((val (assoc word res))) |
|
(acons word (1+ (if val (cdr val) 0)) res))) |
|
result (split/stuff verse))) |
|
|
|
(define (co f g) (lambda (v w) (f (g v) (g w)))) |
|
(define count-words |
|
(compose (cut delete-duplicates <> (co equal? car)) |
|
(cut sort <> (co > cdr)) |
|
(cut fold count '() <>)))
|
|
|