Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/clojure/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Macros 如何向Clojure中的宏添加第二个参数?_Macros_Clojure_With Statement - Fatal编程技术网

Macros 如何向Clojure中的宏添加第二个参数?

Macros 如何向Clojure中的宏添加第二个参数?,macros,clojure,with-statement,Macros,Clojure,With Statement,我有以下带有1个参数的Clojure包装宏: (defmacro with-init-check "Wraps the given statements with an init check." [body] `(if (initialized?) ~body (throw (IllegalStateException. "GeoIP db not initialized.")))) 我想向其中添加ip版本,以便检查是否只初始化了:IPv6或:IPv4。但是,当我尝试此操作时,该参数未

我有以下带有1个参数的Clojure包装宏:

(defmacro with-init-check
"Wraps the given statements with an init check."
[body]
`(if (initialized?)
  ~body
  (throw (IllegalStateException. "GeoIP db not initialized."))))
我想向其中添加
ip版本
,以便检查是否只初始化了
:IPv6
:IPv4
。但是,当我尝试此操作时,该参数未被传递:

(defmacro with-init-check
  "Wraps the given statements with an init check."
  [ip-version body]
  `(if (initialized? ip-version)
    ~body
    (throw (IllegalStateException. "GeoIP db not initialized."))))
当我这样使用它时,我在“if let[location…”行中得到“no-this var”:


如何将
ip版本
获取到
初始化功能?

~
将其解压缩:

(defmacro with-init-check
  "Wraps the given statements with an init check."
  [ip-version body]
  `(if (initialized? ~ip-version) ; unquoted with ~
     ~body
     (throw (IllegalStateException. "GeoIP db not initialized."))))
从docstring推断,您可能还希望允许多个表达式体,并在
do
表达式中取消对它们的拼接:

(defmacro with-init-check
  "Wraps the given statements with an init check."
  [ip-version & body] ; multi-expression bodies with &
  `(if (initialized? ~ip-version)
     (do ~@body) ; unquote-spliced with ~@
     (throw (IllegalStateException. "GeoIP db not initialized."))))

~
将其解压缩:

(defmacro with-init-check
  "Wraps the given statements with an init check."
  [ip-version body]
  `(if (initialized? ~ip-version) ; unquoted with ~
     ~body
     (throw (IllegalStateException. "GeoIP db not initialized."))))
从docstring推断,您可能还希望允许多个表达式体,并在
do
表达式中取消对它们的拼接:

(defmacro with-init-check
  "Wraps the given statements with an init check."
  [ip-version & body] ; multi-expression bodies with &
  `(if (initialized? ~ip-version)
     (do ~@body) ; unquote-spliced with ~@
     (throw (IllegalStateException. "GeoIP db not initialized."))))

以下是联机代码,您可以查看上下文:以下是联机代码,您可以查看上下文: