I am trying to write a macro to rewrite something like this:

  (set-props my-jframe :title "blah" :visible true)

Into calls to the setter methods. I finally settled on this:

  (defmacro set-props [obj & props]
    (let [prop-map (apply hash-map props)]
      `(do
         ~(for [[key val] prop-map]
            `(~(keyword-to-method key) ~obj ~val))
         ~obj)))

where keyword-to-method just converts :title into .setTitle.

The problem is that I also want to have helpers for swing objects like
frames that use this:

  (defn frame [& props]
    (let [f (javax.swing.JFrame.)]
      (apply set-props f props)
      f))

except of course this doesn't work because set-props is a macro so i
can't use apply. I tried doing this instead:

  (defmacro set-props-unflat [obj props]
    `(set-props ~obj [EMAIL PROTECTED]))

  (defn frame [& props]
    (let [f (javax.swing.JFrame.)]
      (set-props-unflat f props)
      f))

but this also doesn't work because the props in the set-props-unflat
call isn't evaluated so i'm just trying to splice in the symbol props.
how can i make this work?

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to