[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/dash f7664c6 352/439: [-let] Add &keys support for cons
From: |
Phillip Lord |
Subject: |
[elpa] externals/dash f7664c6 352/439: [-let] Add &keys support for cons matcher |
Date: |
Tue, 04 Aug 2015 20:30:15 +0000 |
branch: externals/dash
commit f7664c6112161244a5e040135e36e257c1ade096
Author: Matus Goljer <address@hidden>
Commit: Matus Goljer <address@hidden>
[-let] Add &keys support for cons matcher
---
dash.el | 18 ++++++++++++++++--
dev/examples.el | 13 ++++++++++++-
2 files changed, 28 insertions(+), 3 deletions(-)
diff --git a/dash.el b/dash.el
index 6fa8454..2809d3b 100644
--- a/dash.el
+++ b/dash.el
@@ -1246,6 +1246,9 @@ SOURCE is a proper or improper list."
(cond
((symbolp (car match-form))
(cond
+ ((eq (car match-form) '&keys)
+ (when (cdr match-form)
+ (dash--match-kv (cons '&plist (cdr match-form))
(dash--match-cons-get-cdr skip-cdr source))))
((cdr match-form)
(cond
((eq (aref (symbol-name (car match-form)) 0) ?_)
@@ -1256,7 +1259,7 @@ SOURCE is a proper or improper list."
(dash--match-cons-1 (cdr match-form) source)))))
;; Last matching place, no need for shift
(t
- (list (list (car match-form) (dash--match-cons-get-car skip-cdr
source))))))
+ (dash--match (car match-form) (dash--match-cons-get-car skip-cdr
source)))))
(t
(cond
((cdr match-form)
@@ -1388,6 +1391,8 @@ Key-value stores are disambiguated by placing a token
&plist,
(cond
((memq (car match-form) '(&plist &alist &hash))
(dash--match-kv match-form source))
+ ((eq (car match-form) '&keys)
+ (dash--match-kv (cons '&plist (cdr match-form)) source))
(t (dash--match-cons match-form source))))
((vectorp match-form)
(dash--match-vector match-form source))))
@@ -1488,7 +1493,16 @@ Key/value stores:
(&hash key0 a0 ... keyN aN) - bind value mapped by keyK in the
SOURCE hash table to aK. If the
- value is not found, aK is nil."
+ value is not found, aK is nil.
+
+Further, special keyword &keys supports \"inline\" matching of
+plist-like key-value pairs, similarly to &keys keyword of
+`cl-defun'.
+
+ (a1 a2 ... aN &keys key1 b1 ... keyN bK)
+
+This binds N values from the list to a1 ... aN, then interprets
+the cdr as a plist (see key/value matching above)."
(declare (debug ((&rest (sexp form)) body))
(indent 1))
(if (vectorp varlist)
diff --git a/dev/examples.el b/dev/examples.el
index ee03c33..487a4b1 100644
--- a/dev/examples.el
+++ b/dev/examples.el
@@ -745,6 +745,7 @@ new list."
(-let [(a . (b . c)) (cons 1 (cons 2 3))] (list a b c)) => '(1 2 3)
(-let [(_ _ . [a b]) (cons 1 (cons 2 (vector 3 4)))] (list a b)) => '(3 4)
(-let [(_ _ . (a b)) (cons 1 (cons 2 (list 3 4)))] (list a b)) => '(3 4)
+ (-let [([a b] _ _ c) (list (vector 1 2) 3 4 5)] (list a b c)) => '(1 2 5)
;; final cdr optimization
(-let [(((a))) (list (list (list 1 2) 3) 4)] a) => 1
(-let [(((a b) c) d) (list (list (list 1 2) 3) 4)] (list a b c d)) => '(1
2 3 4)
@@ -788,7 +789,17 @@ new list."
(-let [(a b c (d e)) (list 1 2 3 (list 4 5))] (list a b c d e)) => '(1 2 3
4 5)
(-let [(_ _ (_ _ (_ _ a))) (list 1 2 (list 3 4 (list 5 6 7)))] a) => 7
(-let [(_ (_ (_ a))) (list 1 (list 2 (list 3 4)))] a) => 4
- (-let [(_ _ . (&plist :foo a :bar b)) (list 1 2 :bar 2 :foo 1)] (list a
b)) => '(1 2))
+ (-let [(_ _ . (&plist :foo a :bar b)) (list 1 2 :bar 2 :foo 1)] (list a
b)) => '(1 2)
+ ;; &keys support
+ (-let [(_ _ &keys :foo a :bar b) (list 1 2 :bar 4 :foo 3)] (list a b)) =>
'(3 4)
+ (-let [(a _ &keys :foo b :bar c) (list 1 2 :bar 4 :foo 3)] (list a b c))
=> '(1 3 4)
+ (-let [(a _ _ _ &keys :foo b :bar c) (list 1 2 3 4 :bar 6 :foo 5)] (list a
b c)) => '(1 5 6)
+ (-let [(a b &keys :foo c :bar d) (list 1 2 :bar 4 :foo 3)] (list a b c d))
=> '(1 2 3 4)
+ (-let [(a b &keys) (list 1 2 :bar 4 :foo 3)] (list a b)) => '(1 2)
+ (-let [(&keys :foo a :bar b) (list 1 2 :bar 4 :foo 3)] (list a b)) => '(3
4)
+ (-let [(a b (c _ _ &keys :foo [d _ (&alist :bar (e &keys :baz f) :qux
(&plist :fux g))] :mux h) i)
+ (list 1 2 (list 3 'skip 'skip :foo (vector 4 'skip (list (cons :bar
(list 5 :baz 6)) (cons :qux (list :fux 7)))) :mux 8) 9)]
+ (list a b c d e f g h i)) => '(1 2 3 4 5 6 7 8 9))
(defexamples -let*
(-let* (((a . b) (cons 1 2))
- [elpa] externals/dash 7f2b3c7 343/439: [-lambda] test all match-forms before converting to regular lambda, (continued)
- [elpa] externals/dash 7f2b3c7 343/439: [-lambda] test all match-forms before converting to regular lambda, Phillip Lord, 2015/08/04
- [elpa] externals/dash 947ffda 341/439: Add support for &rest match for non-list sequences (like . for improper lists), Phillip Lord, 2015/08/04
- [elpa] externals/dash a4be872 338/439: Add `-let` and `-let*`, Phillip Lord, 2015/08/04
- [elpa] externals/dash 9065e1b 344/439: [-let] Final cdr shift optimization, Phillip Lord, 2015/08/04
- [elpa] externals/dash 6f81492 346/439: [-lambda] Better error-handling, Phillip Lord, 2015/08/04
- [elpa] externals/dash 65a3736 349/439: [-let] Fix improper list non-symbol last argument handler, Phillip Lord, 2015/08/04
- [elpa] externals/dash 4d67b25 345/439: [-let] Do not reinvent `pop', Phillip Lord, 2015/08/04
- [elpa] externals/dash f939201 347/439: [-let] Optimize shifting/binding of unused _ places, Phillip Lord, 2015/08/04
- [elpa] externals/dash 51a0c9f 350/439: [-let] Fix expansion of _ symbols in vector matcher, Phillip Lord, 2015/08/04
- [elpa] externals/dash 0fc5d73 351/439: [-let] Make the cons matcher temp-bind as late as possible, Phillip Lord, 2015/08/04
- [elpa] externals/dash f7664c6 352/439: [-let] Add &keys support for cons matcher,
Phillip Lord <=
- [elpa] externals/dash 6f0bb7d 348/439: [-let] Fix dynamic scoping issue, Phillip Lord, 2015/08/04
- [elpa] externals/dash db7f651 353/439: [-let] Simplify the conditions in dash--match-cons-1, Phillip Lord, 2015/08/04
- [elpa] externals/dash 9ec1a02 354/439: [-let] Abstract the _ test into a function, Phillip Lord, 2015/08/04
- [elpa] externals/dash c1d555b 355/439: [-let] Optimize single-binding of vectors and kv, Phillip Lord, 2015/08/04
- [elpa] externals/dash 0310e0e 359/439: Update docs, Phillip Lord, 2015/08/04
- [elpa] externals/dash 40849a7 357/439: [-let] Remove stale comment, Phillip Lord, 2015/08/04
- [elpa] externals/dash edb1e31 356/439: [-let] Add more tests, Phillip Lord, 2015/08/04
- [elpa] externals/dash 4b63be1 362/439: Declare --mapcat macro before using it. #102, Phillip Lord, 2015/08/04
- [elpa] externals/dash 31f321a 358/439: Release 2.9.0, Phillip Lord, 2015/08/04
- [elpa] externals/dash 2436bf8 361/439: Add debug declaration on -lambda, Phillip Lord, 2015/08/04