Skip to content

Instantly share code, notes, and snippets.

@lispm
Created October 16, 2017 22:19
Show Gist options
  • Save lispm/3a718bf742a5c80fa25142c6c81e573c to your computer and use it in GitHub Desktop.
Save lispm/3a718bf742a5c80fa25142c6c81e573c to your computer and use it in GitHub Desktop.
; 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