From 7446fd15be7c6b489b347d47526eb973f9ed7438 Mon Sep 17 00:00:00 2001 From: "Kevin M. Rosenberg" Date: Sat, 28 Aug 2004 02:15:20 +0000 Subject: [PATCH] r9935: fix update-alist --- lists.lisp | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/lists.lisp b/lists.lisp index 3115dd5..9793f27 100644 --- a/lists.lisp +++ b/lists.lisp @@ -151,19 +151,24 @@ (defmacro update-alist (akey value alist &key (test '#'eql) (key '#'identity)) "Macro to support below (setf get-alist)" - (let ((elem (gensym))) - `(let ((,elem (assoc ,akey ,alist :test ,test :key ,key))) - (if ,elem - (progn - (setf (cdr ,elem) ,value) - ,alist) - (setf ,alist (acons ,akey ,value ,alist)))))) + (let ((elem (gensym "ELEM-")) + (val (gensym "VAL-"))) + `(let ((,elem (assoc ,akey ,alist :test ,test :key ,key)) + (,val ,value)) + (cond + (,elem + (setf (cdr ,elem) ,val)) + (,alist + (setf (cdr (last ,alist)) (list (cons ,akey ,val)))) + (t + (setf ,alist (list (cons ,akey ,val))))) + ,alist))) (defun get-alist (key alist &key (test #'eql)) (cdr (assoc key alist :test test))) (defun (setf get-alist) (value key alist &key (test #'eql)) - "This doesn't work to add a field which alist value is only modified locally" + "This won't work if the alist is NIL." (update-alist key value alist :test test) value) -- 2.34.1