emacs-diffs
[Top][All Lists]
Advanced

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

[Emacs-diffs] master f466b83: * lisp/emacs-lisp/map.el: Fix recent chang


From: Stefan Monnier
Subject: [Emacs-diffs] master f466b83: * lisp/emacs-lisp/map.el: Fix recent changes
Date: Fri, 14 Dec 2018 11:03:18 -0500 (EST)

branch: master
commit f466b83226d3730eb903abb8595bb5ef0d5a5d29
Author: Basil L. Contovounesios <address@hidden>
Commit: Stefan Monnier <address@hidden>

    * lisp/emacs-lisp/map.el: Fix recent changes
    
    (map-empty-p): Add method for lists which avoids computing their
    entire length.
    (map-contains-key): Check for alist membership by comparing against
    DEFAULT argument returned by alist-get.
    (map-put!): Reconcile argument name with that used in docstring.
---
 lisp/emacs-lisp/map.el | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/lisp/emacs-lisp/map.el b/lisp/emacs-lisp/map.el
index 35759db..78cedd3 100644
--- a/lisp/emacs-lisp/map.el
+++ b/lisp/emacs-lisp/map.el
@@ -243,6 +243,9 @@ The default implementation delegates to `map-filter'."
 The default implementation delegates to `map-length'."
   (zerop (map-length map)))
 
+(cl-defmethod map-empty-p ((map list))
+  (null map))
+
 (cl-defgeneric map-contains-key (map key &optional testfn)
   ;; FIXME: The test function to use generally depends on the map object,
   ;; so specifying `testfn' here is problematic: e.g. for hash-tables
@@ -259,7 +262,8 @@ The default implementation delegates to `map-do'."
     nil))
 
 (cl-defmethod map-contains-key ((map list) key &optional testfn)
-  (alist-get key map nil nil (or testfn #'equal)))
+  (let ((v '(nil)))
+    (not (eq v (alist-get key map v nil (or testfn #'equal))))))
 
 (cl-defmethod map-contains-key ((map array) key &optional _testfn)
   (and (integerp key)
@@ -332,16 +336,16 @@ MAP can be a list, hash-table or array."
 ;; FIXME: I wish there was a way to avoid this η-redex!
 (cl-defmethod map-into (map (_type (eql list))) (map-pairs map))
 
-(cl-defgeneric map-put! (map key v)
+(cl-defgeneric map-put! (map key value)
   "Associate KEY with VALUE in MAP and return VALUE.
 If KEY is already present in MAP, replace the associated value
 with VALUE."
   (map--dispatch map
     :list (let ((p (assoc key map)))
-            (if p (setcdr p v)
+            (if p (setcdr p value)
               (error "No place to change the mapping for %S" key)))
-    :hash-table (puthash key v map)
-    :array (aset map key v)))
+    :hash-table (puthash key value map)
+    :array (aset map key value)))
 
 ;; There shouldn't be old source code referring to `map--put', yet we do
 ;; need to keep it for backward compatibility with .elc files where the



reply via email to

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