I would like to set a group of fields in a Java object from Clojure without using reflection at runtime.
This solution (copied from one of the solutions) is close to what I am after:
(defmacro set-all! [obj m]
`(do ~@(map (fn [e] `(set! (. ~obj ~(key e)) ~(val e))) m) ~obj))
(def a (java.awt.Point.))
(set-all! a {x 300 y 100})
This works fine but I want the macro to be able to process a map of fields and values passed in as a var or as a local binding (i.e. not passed directly to the macro as above). The fields should be represented as keywords so the following should work:
(def a (java.awt.Point.))
(def m {:x 300 :y 100})
(set-all! a m)
I can't figure out how to do this using set! and the special dot form within a macro (or any solution that works as above without using reflection at runtime).