emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master 896384b 2/2: Make (setf (map-elt ...)) return the value in the al


From: Lars Ingebrigtsen
Subject: master 896384b 2/2: Make (setf (map-elt ...)) return the value in the alist/plist cases
Date: Thu, 6 May 2021 07:32:11 -0400 (EDT)

branch: master
commit 896384b542cabdc000eafb80c9082830f692bbb2
Author: Lars Ingebrigtsen <larsi@gnus.org>
Commit: Lars Ingebrigtsen <larsi@gnus.org>

    Make (setf (map-elt ...)) return the value in the alist/plist cases
    
    * lisp/emacs-lisp/map.el (map-elt): Return the value in the list
    case (which can signal a `map-not-inplace' error.
    (map-elt): Return the value in the list case, too (bug#47572).
---
 lisp/emacs-lisp/map.el | 32 +++++++++++++++++++-------------
 1 file changed, 19 insertions(+), 13 deletions(-)

diff --git a/lisp/emacs-lisp/map.el b/lisp/emacs-lisp/map.el
index c0cbc7b..5c76fb9 100644
--- a/lisp/emacs-lisp/map.el
+++ b/lisp/emacs-lisp/map.el
@@ -124,7 +124,9 @@ or array."
                           (with-no-warnings (map-put! ,mgetter ,key ,v 
,testfn))
                         (map-not-inplace
                          ,(funcall msetter
-                                   `(map-insert ,mgetter ,key ,v))))))))))
+                                   `(map-insert ,mgetter ,key ,v))
+                         ;; Always return the value.
+                         ,v))))))))
    ;; `testfn' is deprecated.
    (advertised-calling-convention (map key &optional default) "27.1"))
   ;; Can't use `cl-defmethod' with `advertised-calling-convention'.
@@ -429,18 +431,22 @@ To insert an element without modifying MAP, use 
`map-insert'."
   ;; `testfn' only exists for backward compatibility with `map-put'!
   (declare (advertised-calling-convention (map key value) "27.1"))
   ;; Can't use `cl-defmethod' with `advertised-calling-convention'.
-  (map--dispatch map
-    :list
-    (if (map--plist-p map)
-        (plist-put map key value)
-      (let ((oldmap map))
-        (setf (alist-get key map key nil (or testfn #'equal)) value)
-        (unless (eq oldmap map)
-          (signal 'map-not-inplace (list oldmap)))))
-    :hash-table (puthash key value map)
-    ;; FIXME: If `key' is too large, should we signal `map-not-inplace'
-    ;; and let `map-insert' grow the array?
-    :array (aset map key value)))
+  (map--dispatch
+   map
+   :list
+   (progn
+     (if (map--plist-p map)
+         (plist-put map key value)
+       (let ((oldmap map))
+         (setf (alist-get key map key nil (or testfn #'equal)) value)
+         (unless (eq oldmap map)
+           (signal 'map-not-inplace (list oldmap)))))
+     ;; Always return the value.
+     value)
+   :hash-table (puthash key value map)
+   ;; FIXME: If `key' is too large, should we signal `map-not-inplace'
+   ;; and let `map-insert' grow the array?
+   :array (aset map key value)))
 
 (cl-defgeneric map-insert (map key value)
   "Return a new map like MAP except that it associates KEY with VALUE.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]