diff options
author | Nic Ferier <nic@ferrier.me.uk> | 2012-12-28 19:31:12 +0000 |
---|---|---|
committer | Nic Ferier <nic@ferrier.me.uk> | 2012-12-28 19:31:12 +0000 |
commit | 67606a0f2df369ec935733895c845190e94b32fd (patch) | |
tree | bab6dcea5db104d4bd55638f57b95b3d51a2b50e | |
parent | bbcd491f01b71658dad97d684001273761220419 (diff) | |
parent | 92798ee6ebfe3298e44bd3e22c7916ed6ef9994e (diff) |
Merge branch 'master' of github.com:nicferrier/emacs-kv
-rw-r--r-- | kv.el | 19 |
1 files changed, 11 insertions, 8 deletions
@@ -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) |