summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNic Ferier <nic@ferrier.me.uk>2012-12-28 19:31:12 +0000
committerNic Ferier <nic@ferrier.me.uk>2012-12-28 19:31:12 +0000
commit67606a0f2df369ec935733895c845190e94b32fd (patch)
treebab6dcea5db104d4bd55638f57b95b3d51a2b50e
parentbbcd491f01b71658dad97d684001273761220419 (diff)
parent92798ee6ebfe3298e44bd3e22c7916ed6ef9994e (diff)
Merge branch 'master' of github.com:nicferrier/emacs-kv
-rw-r--r--kv.el19
1 files changed, 11 insertions, 8 deletions
diff --git a/kv.el b/kv.el
index 3a7980b..80be11c 100644
--- a/kv.el
+++ b/kv.el
@@ -363,10 +363,17 @@ FUNC is some sort of `assoc' like function."
(defalias 'dotassoc 'kvdotassoc)
(defalias 'dotassq 'kvdotassq)
-(defmacro kvmap-bind (args sexp seq)
- "Bind ARGS to successive elements of SEQ and eval SEXP.
+;; Thank you taylanub for this wonderful abstraction.
+(defmacro kv--destructuring-map (map-function args sequence &rest body)
+ "Helper macro for `destructuring-mapcar' and `destructuring-map'."
+ (declare (indent 3))
+ (let ((entry (gensym)))
+ `(,map-function (lambda (,entry)
+ (destructuring-bind ,args ,entry ,@body))
+ ,sequence)))
-A hybrid of `destructuring-bind' and `mapcar'
+(defmacro kvmap-bind (args sexp seq)
+ "A hybrid of `destructuring-bind' and `mapcar'
ARGS shall be of the form used with `destructuring-bind'
Unlike most other mapping forms this is a macro intended to be
@@ -374,11 +381,7 @@ used for structural transformations, so the expected usage will
be that ARGS describes the structure of the items in SEQ, and
SEXP will describe the structure desired."
(declare (indent 2))
- (let ((entry (gensym)))
- `(mapcar (lambda (,entry)
- (destructuring-bind ,args ,entry ,sexp))
- ,seq)))
-
+ `(kv--destructuring-map mapcar ,args ,seq ,sexp))
(defalias 'map-bind 'kvmap-bind)