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

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

[elpa] externals/dash 1549860 139/316: Merge pull request #296 from cire


From: ELPA Syncer
Subject: [elpa] externals/dash 1549860 139/316: Merge pull request #296 from cireu/fix-hash-opt-expander
Date: Mon, 15 Feb 2021 15:57:44 -0500 (EST)

branch: externals/dash
commit 15498602f42c19c1b8d7f8768f6b998dfd5b3a22
Merge: dca7bdc bbf8016
Author: Matus Goljer <dota.keys@gmail.com>
Commit: GitHub <noreply@github.com>

    Merge pull request #296 from cireu/fix-hash-opt-expander
    
    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..e945fbb 100644
--- a/dash.el
+++ b/dash.el
@@ -1831,7 +1831,9 @@ kv can be any key-value store, such as plist, alist or 
hash-table."
 (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)))
+  (let ((src (make-symbol "src")))
+    `(let ((,src ,source))
+       (when ,src (gethash ,key ,src)))))
 
 (defalias 'dash-expand:&keys 'dash-expand:&plist)
 
diff --git a/dev/examples.el b/dev/examples.el
index f987d45..ff7a92d 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) (push 3 (gethash 'a ht)) ht)))
+      (puthash 'a nil ht)
+      (-let (((&hash? 'a) (funcall fn ht)))
+        a)) => '(3)
     (-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]