diff options
author | Evan Izaksonas-Smith <izak0002@umn.edu> | 2012-10-18 04:29:32 -0500 |
---|---|---|
committer | Evan Izaksonas-Smith <izak0002@umn.edu> | 2012-10-18 04:29:32 -0500 |
commit | 92798ee6ebfe3298e44bd3e22c7916ed6ef9994e (patch) | |
tree | bcf56b08cf611e814cd4b854906b5765c04830a1 | |
parent | 6ea2bae0e0be6767c638c5d1954c158b4070c87d (diff) |
Minor change, added destructuring-bind abstraction
* kv.el: kv--destructuring-map serves as the basis for any future
mapping functions based on destructuring-bind.
-rw-r--r-- | kv.el | 19 |
1 files changed, 11 insertions, 8 deletions
@@ -316,10 +316,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 @@ -327,11 +334,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) |