Skip to content

Instantly share code, notes, and snippets.

@lispm
Created March 19, 2019 14:56
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lispm/adddb10bea51539db1b162d52eb1c323 to your computer and use it in GitHub Desktop.
Save lispm/adddb10bea51539db1b162d52eb1c323 to your computer and use it in GitHub Desktop.
; https://codereview.stackexchange.com/questions/215682/occurrences-frequency-count-exercise-3-ch-3-in-ansi-common-lisp/215711?noredirect=1#comment417480_215711
(defun occurrences (list)
(let ((ht (make-hash-table)))
(let ((holder nil))
(dolist (x list)
(if (not (member x holder :test #'eq))
(progn
(push x holder)
(setf (gethash x ht) 1))
(setf (gethash x ht) (+ 1 (gethash x ht)))))
(let ((holder2 nil))
(dolist (tr holder)
(push (cons tr (gethash tr ht)) holder2))
(sort holder2 #'> :key #'cdr)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment