[英]Attempt to add annotation to defrecord defined class in macro
I'm attempting to create a macro similar to the Quartzite defjob macro that creates the Job class with the @DisallowConcurrentExecution annotation added to it.我正在尝试创建一个类似于 Quartzite defjob 宏的宏,该宏创建了添加了 @DisallowConcurrentExecution 注释的 Job 类。 The code works from the repl, but not inside the macro.代码从 repl 工作,但不在宏内部。
This works...这工作...
user=> (defrecord ^{DisallowConcurrentExecution true} YYY []
#_=> org.quartz.Job
#_=> (execute [this context]
#_=> (println "whoosh!")))
user.YYY
user=> (seq (.getAnnotations YYY))
(#<$Proxy3 @org.quartz.DisallowConcurrentExecution()>)
...but this does not. ……但这不是。
(defmacro defncjob
[jtype args & body]
`(defrecord ^{DisallowConcurrentExecution true} ~jtype []
org.quartz.Job
(execute [this ~@args]
~@body)))
After Rodrigo's suggestion, here is a way to make it work.在 Rodrigo 的建议之后,这里有一种方法可以让它发挥作用。
(defmacro defdcejob
[jtype args & body]
`(defrecord ~(vary-meta jtype assoc `DisallowConcurrentExecution true) []
org.quartz.Job
(execute [this ~@args]
~@body)))
You can't use the ^
reader macro inside macros.您不能在宏中使用^
阅读器宏。 Take a look at this similar question.看看这个类似的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.