【发布时间】:2014-11-04 14:47:33
【问题描述】:
我有以下带有 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-version,以便检查是否仅初始化了: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 such var”:
(defn- lookup-location
"Looks up IP location information."
[ip ip-version]
(with-init-check ip-version
(if-let [location (get-location ip ip-version)]
{:ip ip
:countryCode (.countryCode location)
:countryName (.countryName location)
:region (.region location)
:city (.city location)
:postalCode (.postalCode location)
:latitude (.latitude location)
:longitude (.longitude location)
:dma-code (.dma_code location)
:area-code (.area_code location)
:metro-code (.metro_code location)})))
如何将ip-version 传递给initialized? 函数?
【问题讨论】:
-
这是在线代码,您可以查看上下文:github.com/sventech/clj-geoip/commit/…
标签: macros clojure with-statement