The as-> macro doesn't work with destructuring. This is invalid code:
(-> [1 2] (as-> [a & b] [a (inc b)] [(inc a) b])) Because it is expanded to: (let [[a & b] [1 2] [a & b] [a (inc b)] [a & b] [(inc a) b]] [a & b]) ;; this last expression will not compile But with a little redefinition is possible to make as-> work with destructuring: (defmacro as-> "Binds name to expr, evaluates the first form in the lexical context of that binding, then binds name to that result, repeating for each successive form, returning the result of the last form." {:added "1.5"} [expr name & forms] `(let [~name ~expr ~@(interleave (repeat name) (butlast forms))] ~(last forms))) Now the previous example will expand to: (let [[a & b] [1 2] [a & b] [a (inc b)]] [(inc a) b]) The following example shows why an as-> destructuring compatible macro can be useful. This code parses a defmulti like parameter list by reusing a destructuring form: (defmacro defmulti2 [mm-name & opts] (-> [{} opts] (as-> [m [e & r :as o]] (if (string? e) [(assoc m :docstring e) r] [m o]) (if (map? e) [(assoc m :attr-map e :dispatch-fn (first r)) (next r)] [(assoc m :dispatch-fn e) r]) ... Compare with the original defmulti: (defmacro defmulti [mm-name & options] (let [docstring (if (string? (first options)) (first options) nil) options (if (string? (first options)) (next options) options) m (if (map? (first options)) (first options) {}) options (if (map? (first options)) (next options) options) dispatch-fn (first options) options (next options) m (if docstring (assoc m :doc docstring) m) ... I added a JIRA issue to report & track this (I think) enhacement: http://dev.clojure.org/jira/browse/CLJ-1418 Saludos, Nahuel Greco. -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.