小编Art*_*ein的帖子

使用clojure宏在reify调用中自动创建getter和setter

我正在尝试使用大量(~50)getter和setter方法(一些具有不规则名称)实现一个巨大的Java接口.我认为使用宏来减少代码量会很好.而不是

(def data (atom {:x nil}))
(reify HugeInterface
  (getX [this] (:x @data))
  (setX [this v] (swap! data assoc :x v))) 
Run Code Online (Sandbox Code Playgroud)

我希望能够写作

(def data (atom {:x nil}))
(reify HugeInterface
  (set-and-get getX setX :x))
Run Code Online (Sandbox Code Playgroud)

这个set-and-get宏(或类似的东西)可能吗?我无法让它发挥作用.

macros clojure reify

6
推荐指数
1
解决办法
1173
查看次数

标签 统计

clojure ×1

macros ×1

reify ×1