I have this recursive macro m1 which is called by macro m1-do. The purpose is to generate some function calls.
(defmacro m1 [fname x]
(if (= (count x) 1)
(let [a0 (first x)]
`(~fname ~a0))
(let [[a0 & arest] x]
`((~fname ~a0) (m1 ~fname ~arest)))))
(defmacro m1-do [fname x]
`(do (m1 ~fname ~x)))
This is what I want to achive as a result:
(m1-do f1 (45 98 122 143 215)) =>
(do (f1 45) (f1 98) (f1 122) (f1 143) (f1 215))
But instead I get an additional parenthesis level on each recursion. The first result already has too many of them:
user=> (clojure.walk/macroexpand-all '(m1-do f1 (45 98)))
(do ((f1 45) (f1 98)))
user=> (clojure.walk/macroexpand-all '(m1-do f1 (45 98 122)))
(do ((f1 45) ((f1 98) (f1 122))))
user=> (clojure.walk/macroexpand-all '(m1-do f1 (45 98 122 143)))
(do ((f1 45) ((f1 98) ((f1 122) (f1 143)))))
user=> (clojure.walk/macroexpand-all '(m1-do f1 (45 98 122 143 215)))
(do ((f1 45) ((f1 98) ((f1 122) ((f1 143) (f1 215))))))
The problem seems that each call returns a list, which adds another pair of () and I also tried to develop some flattening function and use it within the macro with no success.
The numbers are only placeholders for the real content which is more complex.
cons: stackoverflow.com/a/5261744/1431660 I could not make it work withconsbecause I run into quoting / unquoting issues.