1

我有功能:

(defn parse-file [stream map-filter]  
  (->> (xml/parse stream)  
       (:content)  
       (func args1)  
       (func args2)  
       (func args3)  
       (attrs)))

我希望具有名为“func”的函数的表达式是由宏生成的。
这里是:

(defmacro gen-macro [map-filter seq]
  `(~@(map #(list 'another-func % %2 seq) map-filter)))

但它返回((func args1) (func args2) (func args2))
如何在生成表达式时删除外括号?

4

1 回答 1

1

听起来您想将生成的列表拼接gen-macro到函数体中parse-file。除非你也parse-file变成一个宏,否则你将无法将语法拼接到它的主体中。

但是,您仍然可以获得所需的功能。你只需要修改gen-macro一下:

(defmacro gen-macro [map-filter seq]
  `(fn [x#] (->> x# ~@(map #(list 'another-func % %2) seq map-filter))))
于 2013-10-08T18:02:15.427 回答