;;; -*- lexical-binding: t -*- ;; ;; this file: ;; https://dataswamp.org/~incal/emacs-init/list.el (require 'cl-lib) (defun count-list (lst) (cl-loop with res = () for l in lst while lst do (push (list l (cl-count l lst)) res) (setq lst (cl-remove l lst)) 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 (lst) (cl-loop with str = "" for l in lst for i from 1 to (length lst) do (setq str (format "%s\n%d. %s (%d)" str i (car l) (cadr l))) 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)