Hello, I am gearing up to write some swing code, specifically some
stuff where I want to use the grid bag layout system, and I remember
something I hated about java:

--c.fill = GridBagConstraints.HORIZONTAL;
c.weightx = 0.5;
c.gridx = 2;
c.gridy = 0;
--

You repeated c all over the place so you didn't dare name it something
reasonable.

I noticed in some closure code this looks about the same (actually
worse):
(set! (.fill c) GridBagConstraints/HORIZONTAL)
    (set! (.anchor c) GridBagConstraints/PAGE_END)
    (set! (.weightx c) 1.0)
    (set! (.weighty c) 1.0)

So I decided to do something about it:

user> c
#<GridBagConstraints java.awt.gridbagconstrai...@f01381>
user> (defmacro sets! [vars & rest]  `(do ~@(map (fn [flds] `(set! (.
~vars ~(first flds)) ~(second flds))) rest)))
nil
user> (macroexpand '(sets! c (fill GridBagConstraints/HORIZONTAL)
(weightx 1.0)))
(do (set! (. c fill) GridBagConstraints/HORIZONTAL) (set! (. c
weightx) 1.0))
user> (sets! c (fill GridBagConstraints/VERTICAL) (weightx 1.0))
1.0
user> (. c fill)
2
user> (sets! c (fill GridBagConstraints/VERTICAL) (weightx 1.0))
1.0
user> (. c fill)
3
user>

Is this a good idea or did I do something ridiculous?  I am a clojure
newb, so please feel free to be quite explicit.

Chris

--~--~---------~--~----~------------~-------~--~----~
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 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to