3

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. The code works from the repl, but not inside the macro.

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.

(defmacro defdcejob
  [jtype args & body]
  `(defrecord ~(vary-meta jtype assoc `DisallowConcurrentExecution true) []
     org.quartz.Job
     (execute [this ~@args]
       ~@body)))
4

1 回答 1

1

您不能在宏中使用^ 阅读器宏。看看这个类似的问题。

于 2015-01-30T13:41:43.233 回答