Last active
December 14, 2015 14:38
-
-
Save hayden-jones/5102052 to your computer and use it in GitHub Desktop.
listfreq
This file contains 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
(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