[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)
- [elpa] externals/dash 3789b15 102/316: Change Emacs tested and supported versions., (continued)
- [elpa] externals/dash 3789b15 102/316: Change Emacs tested and supported versions., ELPA Syncer, 2021/02/15
- [elpa] externals/dash e9919f6 104/316: Release 2.14.0, ELPA Syncer, 2021/02/15
- [elpa] externals/dash a55452a 107/316: Merge pull request #270 from magnars/travis/use-emacs-26, ELPA Syncer, 2021/02/15
- [elpa] externals/dash 14f76df 118/316: Update docs, ELPA Syncer, 2021/02/15
- [elpa] externals/dash 8af9987 116/316: Add '-each-r' and '-each-r-while'., ELPA Syncer, 2021/02/15
- [elpa] externals/dash 8873749 120/316: Improve and simplify right-associative reductions, ELPA Syncer, 2021/02/15
- [elpa] externals/dash e52909f 110/316: Add smarter key destructuring, ELPA Syncer, 2021/02/15
- [elpa] externals/dash 6302243 127/316: Release 2.15.0, ELPA Syncer, 2021/02/15
- [elpa] externals/dash 2758ee7 130/316: Alias `-cons-pair-p` to `-cons-pair?`, ELPA Syncer, 2021/02/15
- [elpa] externals/dash 7267556 075/316: Fix infinite loop in -zip/-interleave when called with no arguments., ELPA Syncer, 2021/02/15
- [elpa] externals/dash fd5980e 136/316: Ensure `hash?` expander evaluates its arg only once.,
ELPA Syncer <=
- [elpa] externals/dash dca7bdc 135/316: Merge pull request #277 from yyoncho/custom-destructoring, ELPA Syncer, 2021/02/15
- [elpa] externals/dash 7854ec7 148/316: Fix quote simplification in docs, ELPA Syncer, 2021/02/15
- [elpa] externals/dash 4ce0e85 149/316: Actually remove mentions of Marmalade, ELPA Syncer, 2021/02/15
- [elpa] externals/dash 0273913 072/316: Update docs, ELPA Syncer, 2021/02/15
- [elpa] externals/dash e9b8611 077/316: Mention that -select and -remove are related, ELPA Syncer, 2021/02/15
- [elpa] externals/dash 8ef3287 078/316: Merge pull request #237 from Wilfred/add-see-also, ELPA Syncer, 2021/02/15
- [elpa] externals/dash 55d8cc9 088/316: Running sum and product can only be computed from non-empty lists, ELPA Syncer, 2021/02/15
- [elpa] externals/dash 1b9061c 090/316: Update docs, ELPA Syncer, 2021/02/15
- [elpa] externals/dash 528e5a5 095/316: Merge pull request #258 from Wilfred/quotes-in-docs, ELPA Syncer, 2021/02/15
- [elpa] externals/dash c77644b 092/316: Regenerate docs, ELPA Syncer, 2021/02/15