;;; -*- lexical-binding: t -*- ;; ;; this file: ;; https://dataswamp.org/~incal/emacs-init/list.el (require 'cl-lib) (defun count-list (l) (cl-loop with res for e in l while l do (push (list e (cl-count e l)) res) (setq l (cl-remove e l)) finally return (cl-sort res #'>= :key #'cadr))) ;; (count-list '(a b c d e a b c d a b c a b a)) ;; -> ((a 5) (b 4) (c 3) (d 2) (e 1)) (defun result-list (l) (cl-loop with str = "" for (e o) in l for i from 1 do (setq str (format "%s\n%d. %s (%d)" str i e o)) finally return (string-trim str))) ;; (result-list (count-list '(a b c d e a b c d a b c a b a))) ;; -> 1. a (5) ;; 2. b (4) ;; 3. c (3) ;; 4. d (2) ;; 5. e (1) (defun lists (&rest l) `(,@l)) ;; (lists) ; () ;; (lists '(a b c) '(d e f)) ; ((a b c) (d e f)) ;; (lists () '(a) '(b c d e f)) ; (() (a) (b c d e f)) (defmacro pushlast (newelt place) (declare (debug (form gv-place))) (macroexp-let2 macroexp-copyable-p x newelt (gv-letplace (getter setter) place (funcall setter `(append ,getter (cons ,x nil)))))) (provide 'list)