我需要幾種方法添加到Clojure的defprotocol
,我寫了幾個相同的Swing組件的Clojure返回多個值:從宏觀
(defprotocol view-methods
(ok-button-add-action-listener [this listener])
(ok-button-set-enabled [this enabled])
(ok-button-set-selected [this selected])
(cancel-button-add-action-listener [this listener])
(cancel-button-set-enabled [this enabled])
(cancel-button-set-selected [this selected])
(other-button-add-action-listener [this listener])
(other-button-set-enabled [this enabled])
(other-button-set-selected [this selected]))
有沒有辦法,我可以寫返回所有宏任何方式三種方法簽名(xxx-button-add-action-listener
,xxx-button-set-enabled
,xxx-button-set-selected
)?
(defprotocol view-methods
(add-methods ok)
(add-methods cancel)
(add-methods other))
該宏需要在每次調用時向增長的defprotocol
添加三個項目。
宏可以返回`[email protected]
並展開「到位」?
我從Stuart Sierra的'do-template'宏中發現(http://clojure.github.com/clojure/clojure.template-api.html)。當我們說話時,我正在試驗它:-)。謝謝。 – Ralph