[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/dash d870282 013/439: Add some tests, and fix the bugs
From: |
Phillip Lord |
Subject: |
[elpa] externals/dash d870282 013/439: Add some tests, and fix the bugs they uncovered. |
Date: |
Tue, 04 Aug 2015 20:25:52 +0000 |
branch: externals/dash
commit d87028298426b896d85fefd140ea0fe79e5668ec
Author: Magnar Sveen <address@hidden>
Commit: Magnar Sveen <address@hidden>
Add some tests, and fix the bugs they uncovered.
---
README.md | 6 ++++--
bang.el | 9 +++++----
tests.el | 8 ++++++++
3 files changed, 17 insertions(+), 6 deletions(-)
diff --git a/README.md b/README.md
index b6c806d..530575c 100644
--- a/README.md
+++ b/README.md
@@ -13,7 +13,7 @@ This is so much a work in progress that you should definitely
not be using it ye
## Anaphoric functions
While `!filter` takes a function to filter the list by, you can also pass
-it a forms - which will then be executed with `it` exposed as the list item.
+it a form - which will then be executed with `it` exposed as the list item.
Here's an example:
(!filter (lambda (num) (= 0 (% num 2))) '(1 2 3 4)) ;; normal version
@@ -22,7 +22,9 @@ Here's an example:
of course the original can also be written like
- (!filter 'even? '(1 2 3 4))
+ (defun even? (num) (= 0 (% num 2)))
+
+ (!filter even? '(1 2 3 4))
which demonstrates the usefulness of both versions.
diff --git a/bang.el b/bang.el
index dc330f9..9f67ed0 100644
--- a/bang.el
+++ b/bang.el
@@ -46,12 +46,13 @@ It should only be set using dynamic scope with a let, like:
(!concat (!map fn list)))
(defmacro !filter (form-or-fn list)
- `(let (!--result)
- (while list
- (let ((it (car list)))
+ `(let ((!--list ,list)
+ (!--result '()))
+ (while !--list
+ (let ((it (car !--list)))
(when ,(if (functionp form-or-fn) (list form-or-fn 'it) (list 'progn
form-or-fn))
(setq !--result (cons it !--result))))
- (setq list (cdr list)))
+ (setq !--list (cdr !--list)))
(nreverse !--result)))
(defun !uniq (list)
diff --git a/tests.el b/tests.el
index 139df00..5f1a9dc 100644
--- a/tests.el
+++ b/tests.el
@@ -1,6 +1,14 @@
(require 'ert)
(require 'bang)
+(defun even? (num) (= 0 (% num 2)))
+
+(ert-deftest filter ()
+ "`!filter' returns a new list of only those elements where the predicate was
non-nil."
+ (should (equal (!filter (lambda (num) (= 0 (% num 2))) '(1 2 3 4)) '(2 4)))
+ (should (equal (!filter (= 0 (% it 2)) '(1 2 3 4)) '(2 4)))
+ (should (equal (!filter even? '(1 2 3 4)) '(2 4))))
+
(ert-deftest difference ()
"`!difference' returns a new list of only elements in list1 that are not in
list2."
(should (equal (!difference '() '()) '()))
- [elpa] externals/dash 300fbc6 002/439: Remove lisp-comments from README, (continued)
- [elpa] externals/dash 300fbc6 002/439: Remove lisp-comments from README, Phillip Lord, 2015/08/04
- [elpa] externals/dash 9a34da8 004/439: Add config for travis-ci, Phillip Lord, 2015/08/04
- [elpa] externals/dash 302c8ea 001/439: Initial commit., Phillip Lord, 2015/08/04
- [elpa] externals/dash 14673a6 007/439: Use nreverse for performance reasons., Phillip Lord, 2015/08/04
- [elpa] externals/dash 7b52951 008/439: Add watchr script to get autotest, Phillip Lord, 2015/08/04
- [elpa] externals/dash 93957f0 006/439: Add travis status icon to README, Phillip Lord, 2015/08/04
- [elpa] externals/dash ad44aee 009/439: Add more tests., Phillip Lord, 2015/08/04
- [elpa] externals/dash 065f76b 005/439: Use ert.el to run on Emacs 23 as well., Phillip Lord, 2015/08/04
- [elpa] externals/dash e720428 010/439: Extract basic iteration form into macro., Phillip Lord, 2015/08/04
- [elpa] externals/dash c229ba8 011/439: Rewrite to anaphoric filter function., Phillip Lord, 2015/08/04
- [elpa] externals/dash d870282 013/439: Add some tests, and fix the bugs they uncovered.,
Phillip Lord <=
- [elpa] externals/dash 3e0ef58 012/439: !filter can now take either a function or form (anaphoric), Phillip Lord, 2015/08/04
- [elpa] externals/dash b24d056 014/439: !map macro, Phillip Lord, 2015/08/04
- [elpa] externals/dash ed2e447 015/439: !reduce macro, Phillip Lord, 2015/08/04
- [elpa] externals/dash f9471e4 016/439: !concat done - one less 'cl dependency, Phillip Lord, 2015/08/04
- [elpa] externals/dash 4201ecd 017/439: Out with remove-if, in with !reject, Phillip Lord, 2015/08/04
- [elpa] externals/dash f5b16e3 018/439: Make !partial have the same quote-less API as the rest of bang., Phillip Lord, 2015/08/04
- [elpa] externals/dash a02b6c1 021/439: Add note about no 'cl required., Phillip Lord, 2015/08/04
- [elpa] externals/dash 07de30e 019/439: !mapcat macro, and with that: goodbye 'cl!, Phillip Lord, 2015/08/04
- [elpa] externals/dash 52815c5 020/439: Add documentation, Phillip Lord, 2015/08/04
- [elpa] externals/dash 73204ca 022/439: Change !contains-p to !contains? to match clojure api., Phillip Lord, 2015/08/04