summaryrefslogtreecommitdiff
path: root/lisp/emacs-lisp
diff options
context:
space:
mode:
authorNicolas Petton <nicolas@petton.fr>2016-03-25 15:09:04 +0100
committerNicolas Petton <nicolas@petton.fr>2016-03-25 15:11:23 +0100
commit3a13472adee7117e5af1249e41f6e8db9c473603 (patch)
tree2bb3ab1fd87273ff2a906d95d3c0ea64c8a4f0e5 /lisp/emacs-lisp
parent422c3dadce6dbd33ced2024782438af68c5756de (diff)
downloademacs-3a13472adee7117e5af1249e41f6e8db9c473603.tar.gz
emacs-3a13472adee7117e5af1249e41f6e8db9c473603.tar.bz2
emacs-3a13472adee7117e5af1249e41f6e8db9c473603.zip
Fix map-put and map-delete for alists (Bug#23105)
* lisp/emacs-lisp/map.el (map-put): Do not bind the evaluated place expression to a new symbol. * test/lisp/emacs-lisp/map-tests.el: Add a regression test.
Diffstat (limited to 'lisp/emacs-lisp')
-rw-r--r--lisp/emacs-lisp/map.el36
1 files changed, 10 insertions, 26 deletions
diff --git a/lisp/emacs-lisp/map.el b/lisp/emacs-lisp/map.el
index ec8d3d79d9f..ba15a65f5e1 100644
--- a/lisp/emacs-lisp/map.el
+++ b/lisp/emacs-lisp/map.el
@@ -123,33 +123,26 @@ MAP can be a list, hash-table or array."
default)))
(defmacro map-put (map key value)
- "Associate KEY with VALUE in MAP and return MAP.
+ "Associate KEY with VALUE in MAP and return VALUE.
If KEY is already present in MAP, replace the associated value
with VALUE.
MAP can be a list, hash-table or array."
- (macroexp-let2 nil map map
- `(progn
- (setf (map-elt ,map ,key) ,value)
- ,map)))
+ `(setf (map-elt ,map ,key) ,value))
-(defmacro map-delete (map key)
+(defun map-delete (map key)
"Delete KEY from MAP and return MAP.
No error is signaled if KEY is not a key of MAP. If MAP is an
array, store nil at the index KEY.
MAP can be a list, hash-table or array."
- (declare (debug t))
- (gv-letplace (mgetter msetter) `(gv-delay-error ,map)
- (macroexp-let2 nil key key
- `(if (not (listp ,mgetter))
- (map--delete ,mgetter ,key)
- ;; The alist case is special, since it can't be handled by the
- ;; map--delete function.
- (setf (alist-get ,key (gv-synthetic-place ,mgetter ,msetter)
- nil t)
- nil)
- ,mgetter))))
+ (map--dispatch map
+ :list (setf (alist-get key map nil t) nil)
+ :hash-table (remhash key map)
+ :array (and (>= key 0)
+ (<= key (seq-length map))
+ (aset map key nil)))
+ map)
(defun map-nested-elt (map keys &optional default)
"Traverse MAP using KEYS and return the looked up value or DEFAULT if nil.
@@ -337,15 +330,6 @@ MAP can be a list, hash-table or array."
(cdr pair)))
map))
-(defun map--delete (map key)
- (map--dispatch map
- :list (error "No place to remove the mapping for %S" key)
- :hash-table (remhash key map)
- :array (and (>= key 0)
- (<= key (seq-length map))
- (aset map key nil)))
- map)
-
(defun map--apply-hash-table (function map)
"Private function used to apply FUNCTION over MAP, MAP being a hash-table."
(let (result)