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

[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))



reply via email to

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