Macros 从clojure宏返回多个值

Macros 从clojure宏返回多个值,macros,clojure,Macros,Clojure,我需要向Clojuredefprotocol中添加几个方法,我正在为几个相同的Swing组件编写这些方法: (defprotocol view-methods (ok-button-add-action-listener [this listener]) (ok-button-set-enabled [this enabled]) (ok-button-set-selected [this selected]) (cancel

我需要向Clojure
defprotocol
中添加几个方法,我正在为几个相同的Swing组件编写这些方法:

(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按钮添加操作侦听器
xxx按钮集已启用
xxx按钮集已选择

每次调用时,此宏需要向不断增长的
defprotocol
中添加三项


宏能否返回`~@a-list并“就地”展开?

我认为宏必须展开为一种形式,因此不能按照您所描述的方式进行

但是,并非所有内容都丢失了,因为在顶层使用一个类似以下内容的宏肯定是可能的:

(defmacro build-button-protocol [name & method-specs]
    ....)
您可以按如下方式使用:

(build-button-protocol view-methods
  (add-methods ok)
  (add-methods cancel)
  (add-methods other))

是的,您只需要在
(do…
)中展开宏,Clojure编译器将把
do
子项作为顶级表单序列进行线程处理。

我想到了这一点,但我还需要向协议中添加其他方法。通过查看Stuart Sierra的
do模板
宏(),我发现了这一点。我们说话的时候,我正在用它做实验:-)。谢谢
(build-button-protocol view-methods
  (add-methods ok)
  (add-methods cancel)
  (add-methods other))