word-count.el (594B)
1 ;;; word-count.el --- word-count Exercise (exercism) 2 3 ;;; Commentary: 4 5 ;;; Code: 6 7 (defun extract-words (s) 8 "Extract lowercased words from S. 9 Splits on whitespace, removes non alphanumeric characters." 10 (split-string (replace-regexp-in-string "[^[:alnum:]_-]" " " (downcase s)))) 11 12 (defun word-count (s) 13 "Return an alist word count of words in S." 14 (let ((word-count ())) 15 (dolist (w (extract-words s) word-count) 16 (let ((entry (assoc w word-count))) 17 (if entry (cl-incf (cdr entry)) 18 (push (cons w 1) word-count)))))) 19 20 (provide 'word-count) 21 ;;; word-count.el ends here