Hi, I am trying to define a macro something like this:

(defwidget
    (vlayout
        (create-button b)
        (create-label l))
    (on-event b "pressed" (fn [] (.setText l "Hello World"))))

After a lot of messing around (I am learning all the time here!) I
have a version of defwidget that generates the code I want but I get
"Can't let qualified name" errors.

This is where my understanding of macros is giving me problems.  I
want the forms inside "vlayout"  to expand to local vars in a let
form.  The above example would expand to:

(let [b (create-button)
        l (create-label)]
    (on-event b "pressed" (fn [] (.setText l "Hello World"))

where on-event is just a function.  So I want to build the let form
then have the body use the local vars defined by the let form.  So if
I understand correctly I explicity want to allow variable capture,
don't I?  I am not sure how to achieve what I need.  Clojure
automatically qualifies the vars and I just want to just turn off that
behaviour I think...

For completeness, here's the source for my macro but beware - it's
incomplete, very messy and probably unreadable!

(defmacro defwidget [& body]
  `(let [panel# (javax.swing.JPanel.)
         ~@(flat1 (map (fn [[type inst]] [inst (list type)]) (rest (first 
body))))]
    ~(second body)
    (doto panel#
      (.setLayout (javax.swing.BoxLayout. panel# javax.swing.BoxLayout/Y_AXIS))
      (.add l)
      (.add b))))

(defn flat1 [coll]
     (mapcat #(if (coll? %) % [%]) coll))

The code that generates the let form is on line 3.  I need some way of
getting "inst" to expand to its value without Clojure qualifying it.
I think that's what I need anyway - this is all very confusing to me
still!!

I'm sure there are lots of ways to clean this macro up - comments welcome.

Cheers,
Paul.
-- 
Iode Software Ltd, registered in England No. 6299803.

Registered Office Address: 12 Sancroft Drive, Houghton-le-Spring, Tyne
& Wear, DH5 8NE.

This message is intended only for the use of the person(s) ("the
intended recipient(s)") to whom it is addressed. It may contain
information which is privileged and confidential within the meaning of
applicable law. If you are not the intended recipient, please contact
the sender as soon as possible. The views expressed in this
communication may not necessarily be the views held by The Company.

--~--~---------~--~----~------------~-------~--~----~
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