Hi Richard,

As you probably know, Clojure java interop requires the method to be a
symbol:
user=> (. 5 toString)
"5"

So if you want to invoke a method from a string, you can convert the
string to symbol first:
user=> (symbol "toString")
toString

Great! but (. 5 (symbol "toString")) wont work because (symbol
"toString") is not evaluated. Instead it gets transformed into
5.symbol("toString") which is not what we want :( :(
However with a little trickery we can still do it (please excuse
ugliness - my macro-fu is weak):

(defmacro my-invoke [method-str instance & args]
  `(. ~instance ~(symbol method-str) ~...@args))

user=> (my-invoke "toString" 5)
"5"



Regards,
Tim.
--~--~---------~--~----~------------~-------~--~----~
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