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)))
walen
  • 7,103
  • 2
  • 37
  • 58
BillRobertson42
  • 12,602
  • 4
  • 40
  • 57

1 Answers1

1

You can't use the ^ reader macro inside macros. Take a look at this similar question.

Community
  • 1
  • 1
Rodrigo Taboada
  • 2,727
  • 4
  • 24
  • 27