0
我有以下Clojure的包裝與宏觀參數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."))))
當我使用它像這樣,我得到「沒有這樣的變種」的「如果 - 讓[位置...」行:
(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?
函數?
下面的代碼在線,所以你可以看到上下文: https://github.com/sventech/clj-geoip/commit/e4a9a2c4801b13143ea7f3270232d03eb419308d – sventechie 2014-11-04 14:49:16