宏传递的符号不是值

时间:2019-03-04 19:59:44

标签: clojure macros

我正在处理一个宏,该宏将{"string-name" 'some-val}的映射解包为let绑定。例如:

(with-locals {"a" 4} (inc a))
; => 5

在上述情况下,我当前的代码可以正常工作:

(defmacro with-locals [m & body]
  `(let ~(into [] (mapcat (fn [[s v]] [(symbol s) v]) m))
    ~@body))

(macroexpand-1 '(with-locals {"a" 1} (inc a)))
; => (clojure.core/let [a 1] (inc a))

但是,当地图没有直接传递到宏时,我遇到了问题。

(let [local-vals {"a" 4}] (macroexpand-1 '(with-locals local-vals (inc a))))
; Syntax error macroexpanding with-locals at xxx.
; Don't know how to create ISeq from: clojure.lang.Symbol

我想念什么?难道无法按照我想要的方式制作此宏,因为它们在编译时运行了吗?

0 个答案:

没有答案