(defun rank (l &optional (n 0) (h (make-hash-table))) (labels ((pop-repeats (b4 l sum) (cond ((null l) n) ((eql b4 (car l)) (incf n) (pop-repeats b4 (cdr l) (+ sum n)) (t (/ sum n)))))) (if (null l) h (let ((head (pop l))) (setf (gethash head h) (pop-repeats head l n)) (rank l (1+ n) h)))))