On Thu, Jun 18, 2009 at 11:33:54AM -0700, hoeck wrote:
> 
> Hi,
> 
> proxy is a macro, where you supply the method definitions according to
> its docstring in the following format:
> 
> user> (doc proxy)
>   ...
>   f => (name [params*] body) or
>   (name ([params*] body) ([params+] body) ...)
>   ...
> 
> so it expects: a list of name vector body*
> 
> > Unfortunately, I get an exception
> >
> >     java.lang.RuntimeException: java.lang.UnsupportedOperationException: 
> > nth not supported on this type: Symbol (NO_SOURCE_FILE:2)
> 
> you wrote:
> >          (proxy [SHDocVw.events.DWebBrowserEvents] []
> >            (create-print-method-call beforeNavigate)))
> so instead of a vector, proxy finds a symbol: beforenavigate
> and can't call nth on that (that's what the exception said)
> 
> So you could include the whole proxy call in your macro, like:
> 
> (defmacro proxy-create-print-method-call
>   [name & body]
>   `(proxy [SHDocVw.events.DWebBrowserEvents] []
>      (~name [& args#]
>             (println (str '~name
>                          "("
>                          (str-join ", " (map (fn [arg#] (pr-str arg#))
> args#))
>                          ")")))
>      ~...@body))
> 
> to remove the boilerplate from your proxy code.
> 

Excellent!  Thanks so much!

I got the your first example working and will have to try to digest
the rest tonight.  It looks like exactly what I need.

Thanks again!
Jeff

> Or maybe you would like use sth. like this
> (at least, I found this to be useful from time to time):
> 
> (defmacro fproxy
>   "like proxy but take a hashmap: {method-name method-fn, ...}
>   ex.: (.count (fproxy [clojure.lang.IPersistentVector] [] {'count (fn
> [this] 99)})) -> 99."
>   [class-and-interfaces constructor-args method-name-fn-map]
>   `(let [pc# (proxy ~class-and-interfaces ~constructor-args)]
>      (update-proxy pc# ~method-name-fn-map)
>      pc#))
> 
> (def default-before-navigate-method
>      {"beforeNavigate" (fn [this & args]
>                             (println (str 'beforeNavigate
>                                           "("
>                                           (str-join ", " (map #(pr-str
> %) args))
>                                           ")")))})
> 
> (fproxy [SHDocVw.events.DWebBrowserEvents] []
>         (merge default-before-navigate-method
>                {"anotherMethod" (fn [this ..] ...)}))
> 
> to make proxy generation more dynamic & functional.
> 
> Erik
> 
> > 

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your 
first post.
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