[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/dash 8f9fc41 340/439: Add support for multiple input ar
From: |
Phillip Lord |
Subject: |
[elpa] externals/dash 8f9fc41 340/439: Add support for multiple input arguments to -lambda |
Date: |
Tue, 04 Aug 2015 20:29:58 +0000 |
branch: externals/dash
commit 8f9fc4113d90b8f48192b56ea6d60db1bce2dc87
Author: Matus Goljer <address@hidden>
Commit: Matus Goljer <address@hidden>
Add support for multiple input arguments to -lambda
---
README.md | 2 +-
dash.el | 8 ++++++--
dev/examples.el | 2 ++
3 files changed, 9 insertions(+), 3 deletions(-)
diff --git a/README.md b/README.md
index a065eec..5b425ac 100644
--- a/README.md
+++ b/README.md
@@ -1822,7 +1822,7 @@ See `-let` for the description of destructuring mechanism.
```cl
(-map (-lambda ((x y)) (+ x y)) '((1 2) (3 4) (5 6))) ;; => '(3 7 11)
(-map (-lambda ([x y]) (+ x y)) '([1 2] [3 4] [5 6])) ;; => '(3 7 11)
-(-map (-lambda ((&plist :a a :b b)) (+ a b)) '((:a 1 :b 2) (:a 3 :b 4) (:a 5
:b 6))) ;; => '(3 7 11)
+(funcall (-lambda ((_ . a) (_ . b)) (-concat a b)) '(1 2 3) '(4 5 6)) ;; =>
'(2 3 5 6)
```
diff --git a/dash.el b/dash.el
index 9b32668..7efe2b7 100644
--- a/dash.el
+++ b/dash.el
@@ -1426,8 +1426,12 @@ See `-let' for the description of destructuring
mechanism."
(symbolp (car match-form)))
`(lambda ,match-form ,@body))
(t
- `(lambda (x)
- (-let* ((,@match-form x)) ,@body)))))
+ (let* ((inputs (--map-indexed (list it (make-symbol (format "input%d"
it-index))) match-form)))
+ ;; TODO: because inputs to the lambda are evaluated only once,
+ ;; -let* need not to create the extra bindings to ensure that.
+ ;; We should find a way to optimize that. Not critical however.
+ `(lambda ,(--map (cadr it) inputs)
+ (-let* ,inputs ,@body))))))
(defun -distinct (list)
"Return a new list with all duplicates removed.
diff --git a/dev/examples.el b/dev/examples.el
index 2bd0ee1..d78bccc 100644
--- a/dev/examples.el
+++ b/dev/examples.el
@@ -757,8 +757,10 @@ new list."
(defexamples -lambda
(-map (-lambda ((x y)) (+ x y)) '((1 2) (3 4) (5 6))) => '(3 7 11)
(-map (-lambda ([x y]) (+ x y)) '([1 2] [3 4] [5 6])) => '(3 7 11)
+ (funcall (-lambda ((_ . a) (_ . b)) (-concat a b)) '(1 2 3) '(4 5 6)) =>
'(2 3 5 6)
(-map (-lambda ((&plist :a a :b b)) (+ a b)) '((:a 1 :b 2) (:a 3 :b 4) (:a
5 :b 6))) => '(3 7 11)
(-map (-lambda (x) (let ((k (car x)) (v (cadr x))) (+ k v))) '((1 2) (3 4)
(5 6))) => '(3 7 11)
+ (funcall (-lambda ((a) (b)) (+ a b)) '(1 2 3) '(4 5 6)) => 5
(condition-case nil (progn (-lambda a t) (error "previous form should
error")) (error t)) => t))
(def-example-group "Side-effects"
- [elpa] externals/dash 25c114c 330/439: Implementing a shallow copy counterpart to -clone., (continued)
- [elpa] externals/dash 25c114c 330/439: Implementing a shallow copy counterpart to -clone., Phillip Lord, 2015/08/04
- [elpa] externals/dash 6fc652d 331/439: Merge pull request #95 from Wilfred/shallow-copy-function, Phillip Lord, 2015/08/04
- [elpa] externals/dash d37947a 332/439: Add -tree-seq, Phillip Lord, 2015/08/04
- [elpa] externals/dash 166bccd 333/439: Add -tree-map-nodes, Phillip Lord, 2015/08/04
- [elpa] externals/dash 3adad97 334/439: Add -non-nil, Phillip Lord, 2015/08/04
- [elpa] externals/dash ab99be6 335/439: Add -fix, Phillip Lord, 2015/08/04
- [elpa] externals/dash 2626840 336/439: Add -fixfn, Phillip Lord, 2015/08/04
- [elpa] externals/dash c6b92ae 324/439: Reorder the examples into more meaningful blocks, Phillip Lord, 2015/08/04
- [elpa] externals/dash b1e585d 337/439: Update copyright notice, Phillip Lord, 2015/08/04
- [elpa] externals/dash f0831d3 339/439: Add -lambda, Phillip Lord, 2015/08/04
- [elpa] externals/dash 8f9fc41 340/439: Add support for multiple input arguments to -lambda,
Phillip Lord <=
- [elpa] externals/dash 05fa92f 342/439: [-let] Transpose nreverse/flatten, Phillip Lord, 2015/08/04
- [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