diff options
author | Artur Malabarba <bruce.connor.am@gmail.com> | 2014-11-18 16:35:19 +0000 |
---|---|---|
committer | Artur Malabarba <bruce.connor.am@gmail.com> | 2014-11-18 16:35:19 +0000 |
commit | bb2d155ef7ae73a00eba53ed7e0d1acee6c0902e (patch) | |
tree | 88206361c8bc587c086bc1099618bc3be563c301 | |
parent | 876ab80a8b62214bb608716241c525ffc2ea0cf3 (diff) |
Define sorted insertion macro.
-rw-r--r-- | sx.el | 15 |
1 files changed, 15 insertions, 0 deletions
@@ -27,6 +27,21 @@ ;;; Utility Functions +(defmacro sx-sorted-insert-skip-first (newelt list &optional predicate) + "Inserted NEWELT into LIST sorted by PREDICATE. +This is designed for the (site id id ...) lists. So the first car +is intentionally skipped." + `(let ((tail ,list) + (x ,newelt)) + ;; The first element is never less-than. + (while (and + ;; We're at the end. + (cdr-safe tail) + ;; We're at the right place. + (,(or predicate #'<) x (cadr tail))) + (setq tail (cdr tail))) + (setcdr tail (cons x (cdr tail))))) + (defun sx-message (format-string &rest args) "Display a message" (message "[stack] %s" (apply #'format format-string args))) |