emacs-elpa-diffs
[Top][All Lists]
Advanced

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

[elpa] externals/dash fd5980e 136/316: Ensure `hash?` expander evaluates


From: ELPA Syncer
Subject: [elpa] externals/dash fd5980e 136/316: Ensure `hash?` expander evaluates its arg only once.
Date: Mon, 15 Feb 2021 15:57:43 -0500 (EST)

branch: externals/dash
commit fd5980eacecdad9723846da7ef33bee3416b63a6
Author: citreu <all_but_last@163.com>
Commit: citreu <all_but_last@163.com>

    Ensure `hash?` expander evaluates its arg only once.
---
 dash.el         | 4 +++-
 dev/examples.el | 6 ++++++
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/dash.el b/dash.el
index 4b0857f..411e052 100644
--- a/dash.el
+++ b/dash.el
@@ -1828,10 +1828,12 @@ kv can be any key-value store, such as plist, alist or 
hash-table."
   "Generate extracting KEY from SOURCE for &alist destructuring."
   `(cdr (assoc ,key ,source)))
 
+(require 'macroexp)
+
 (defun dash-expand:&hash? (key source)
   "Generate extracting KEY from SOURCE for &hash? destructuring.
 Similar to &hash but check whether the map is not nil."
-  `(when ,source (gethash ,key ,source)))
+  (macroexp-let2 nil source source `(when ,source (gethash ,key ,source))))
 
 (defalias 'dash-expand:&keys 'dash-expand:&plist)
 
diff --git a/dev/examples.el b/dev/examples.el
index f987d45..5718315 100644
--- a/dev/examples.el
+++ b/dev/examples.el
@@ -1150,6 +1150,12 @@ new list."
       (puthash :bar 2 hash)
       (-let (((&hash :foo :bar) hash)) (list foo bar))) => '(1 2)
     (-let (((&hash :foo (&hash? :bar)) (make-hash-table)))) => nil
+    ;; Ensure `hash?' expander evaluates its arg only once
+    (let* ((ht (make-hash-table :test #'equal))
+           (fn (lambda (ht) (cl-incf (gethash 'a ht)) ht)))
+      (puthash 'a 3 ht)
+      (-let (((&hash? 'a) (funcall fn ht)))
+        a)) => 4
     (-let (((_ &keys :foo :bar) (list 'ignored :foo 1 :bar 2))) (list foo 
bar)) => '(1 2)
     ;;; go over all the variations of match-form derivation
     (-let (((&plist :foo foo :bar) (list :foo 1 :bar 2))) (list foo bar)) => 
'(1 2)



reply via email to

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