下面定義的宏,transform!
似乎適用於=> (transform! ["foo" 1 2 3])
。目的是獲取一個列表,第一個元素是一個表示名稱空間中的函數的字符串。然後把所有東西都包裝成swap!
。使用交換內的字符串調用Clojure函數?
問題是transform!
不適用於=> (transform! coll)
,其中(def coll ["foo" 1 2 3])
。我得到這個神祕異常:
#<UnsupportedOperationException java.lang.UnsupportedOperationException: nth not supported on this type: Symbol>
功能:
(defmacro transform!
" Takes string input and update data with corresponding command function.
"
[[f & args]] ;; note double brackets
`(swap! *image* ~(ns-resolve *ns* (symbol f)) [email protected]))
我覺得奇怪的是它爲一個案件,而不是其他。