HI,

I have several calls to addListener, for which I have to create a
proxy::
(.. (WPushButton. "Greet me" root) clicked (addListener  wapp
    (proxy [Signal1$Listener] [] (trigger [ mouse-event ] (.setText
result-text (.getText line-edit)) ))))

I think this is code elligible for simplification with a macro
(correct me if I'm wrong).

In the example above, the macro has to expand to:
(proxy [Signal1$Listener] [] (trigger [ mouse-event ] (.setText result-
text (.getText line-edit))))

but there are other cases, according to the number of argument passed
to trigger:

(proxy [Signal$Listener] [] (trigger [ ] (.setText result-text
(.getText line-edit))))
(proxy [Signal2$Listener] [] (trigger [ arg1 arg2 ]  ...  ))
(proxy [Signal3$Listener] [] (trigger [ arg1 arg2 arg3 ]  ...  ))


Here is what I've done for now:

(defmacro deflistener [ interfaces trigger-args & body]
  `(proxy [ ~...@interfaces ] [] (trigger [...@trigger-args] ~...@body))
)

Which can be used like this:
( deflistener (Signal1$Listener) (mouse-event)  (.setText result-text
(.getText line-edit)) ))

It takes as arguments
* the list of interfaces it implements (currently necessary for
http://www.assembla.com/spaces/clojure/tickets/181)
* the list of arguments passed to the trigger method implemented
* the body of the implementation of trigger

Here are the questions that arise:

* I thought I could and should do away with trigger-args, but if I use
gensyms in the macro to define the arguments received by trigger, how
can I get to the argument values in the code of the method?

* if it implements  SignalX$Listener, trigger takes X arguments. How
can implement that with one macro, and still have access to these
arguments in the forms I pass as body of trigger?

Thanks for your help

Raphaƫl
--~--~---------~--~----~------------~-------~--~----~
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
Note that posts from new members are moderated - please be patient with your 
first post.
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