Add association if `key' is not in `alist' and replace all accociation with
authorOleksandr Gavenko <gavenkoa@gmail.com>
Sun, 01 Nov 2020 14:26:50 +0200
changeset 1631 f6eae5ebf7d9
parent 1630 8e99c0b3b772
child 1632 9189d278b075
Add association if `key' is not in `alist' and replace all accociation with single, if there is `key'.
.emacs-my
--- a/.emacs-my	Tue Oct 13 21:24:58 2020 +0300
+++ b/.emacs-my	Sun Nov 01 14:26:50 2020 +0200
@@ -182,6 +182,14 @@
     x2
     ) )
 
+(defun my-assoc-push (key value alist)
+  "Add association if `key' is not in `alist' and replace all
+accociation with single, if there is `key'."
+  (when (not (symbolp alist)) (error "alist is not a symbol."))
+  (set alist
+       (cons (cons key value)
+             (cl-remove key (symbol-value alist) :key #'car :test #'equal))))
+
 (unless (fboundp 'ignore-errors)
   (defmacro ignore-errors (&rest body)
     "Execute BODY; if an error occurs, return nil.