Created
October 16, 2017 22:19
-
-
Save lispm/3a718bf742a5c80fa25142c6c81e573c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; https://github.com/inconvergent/snek/blob/master/utils/count.lisp | |
(defun make-counter (&optional ll) | |
(let ((c (make-hash-table :test #'equal))) | |
(loop for a in ll do (counter-add c a)) | |
c)) | |
(defun counter-add (c a) | |
(incf (gethash a c 0))) | |
(defun counter-show (c) | |
(loop with tot = (float (loop for n being the hash-values of c summing n)) | |
for a being the hash-keys of c using (hash-value n) | |
do (format t "~a: ~a, ~a~%" a n (/ (gethash a c) tot)))) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment