Skip to content

Instantly share code, notes, and snippets.

@hayden-jones
Last active December 14, 2015 14:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hayden-jones/5102052 to your computer and use it in GitHub Desktop.
Save hayden-jones/5102052 to your computer and use it in GitHub Desktop.
listfreq
(defun howmany (obj lst)
(let ((res
(remove-if-not #'(lambda (x)
(if (equal x obj) t))
lst)))
(length res)))
;; we used remove-if-not to do this instead of dolist because it was just a bit easier
(defun uniques (lst)
(let ((res '()))
(dolist (x lst)
(setf res (adjoin x res)))
res))
(defun listfreq (lst)
(let ((res '()))
(let ((vals (uniques lst)))
(dolist (x vals)
(push (list x (howmany x lst)) res)))
res))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment