(defun freq-list (alist &optional (num.bins 10)) "Given a list of numbers, count frequencies." (let* ((slist (sort (copy-list alist) #'<)) (size (/ (- (car (last slist)) (first slist)) num.bins)) (max (first slist)) (al nil) (at 0) (curr 0) (next 1)) (dotimes (i num.bins) (setf al (append al (list `(,max . 0)))) (setf max (+ max size))) (setf curr (car (nth at al)) next (car (nth (+ at 1) al))) (dolist (item slist) (if (not (<= curr item next)) (progn (setf at 0) (dolist (bin al) (if (< (car bin) item) (incf at))) (if (< (+ at 1) num.bins) (progn (setf curr (car (nth at al)) next (car (nth (+ at 1) al)))) (setf curr (car (nth (- at 1) al)) next most-positive-fixnum)))) (setf (cdr (assoc curr al)) (+ (cdr (assoc curr al)) 1))) al)) (defun demo-freq-list () (freq-list '(4 3 56 2 3 4 7 15 32 4 25 25 25 25 25)))