相关疑难解决方法(0)

在clojure中,如何将宏应用于列表?

clojure,apply不能应用于宏.例如,(apply and [true false])引发异常.我正在考虑以下解决方法:

(defmacro apply-macro[func args] `(~func ~@args))
Run Code Online (Sandbox Code Playgroud)

乍一看,它看起来效果很好:

(apply-macro and [true 5]); 5
(apply-macro and [true 5 0]); 0
(let [a 0] (apply-macro and [true a])); 0
Run Code Online (Sandbox Code Playgroud)

但是,当我向它传递一个指向向量的变量时,它就崩溃了.

(let [a [true]] (apply-macro and a));  java.lang.IllegalArgumentException:
   ;Don't know how to create ISeq from: clojure.lang.Symbol
Run Code Online (Sandbox Code Playgroud)

多么令人失望!!!!

知道怎么解决apply-macro

clojure

27
推荐指数
2
解决办法
4551
查看次数

标签 统计

clojure ×1