From: Kevin M. Rosenberg Date: Sat, 28 Aug 2004 02:15:20 +0000 (+0000) Subject: r9935: fix update-alist X-Git-Tag: v1.96~63 X-Git-Url: http://git.kpe.io/?p=kmrcl.git;a=commitdiff_plain;h=7446fd15be7c6b489b347d47526eb973f9ed7438 r9935: fix update-alist --- 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)