Re: How to invoke java method obtained using clojure.reflect

2014-02-13 Thread zcaudate
Try my new library. It makes reflection really easy to use http://github.com/zcaudate/iroh -- 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 - p

Re: How to invoke java method obtained using clojure.reflect

2013-02-12 Thread Aaron Cohen
You're actually probably better off using clojure's reflector (clojure.lang.Reflector/invokeStaticMethod ...) or (clojure.lang.Reflector/invokeInstanceMethod ...) That way you get type coercions that match clojure's behaviour. On Tue, Feb 12, 2013 at 9:16 AM, juan.facorro wrote: > Awesome :) >

Re: How to invoke java method obtained using clojure.reflect

2013-02-12 Thread Pablo Nussembaum
Hey, I really appreciate your help guys. This is very useful. On 02/12/2013 10:45 AM, Meikel Brandmeyer (kotarak) wrote: > You can also do away with the argument names. You just need the number of > arguments. > > (defn call-fn > [class method n-args] > (let [o(gensym) > args (rep

Re: How to invoke java method obtained using clojure.reflect

2013-02-12 Thread juan.facorro
Awesome :) On Tuesday, February 12, 2013 9:51:01 AM UTC-3, Meikel Brandmeyer (kotarak) wrote: > > Hi, > > if you want to resort to eval you can define your own function on the fly. > > (defn call-fn > [& args] > {:arglists ([class method & args])} > (let [o (gensym) > [class method

Re: How to invoke java method obtained using clojure.reflect

2013-02-12 Thread Meikel Brandmeyer (kotarak)
You can also do away with the argument names. You just need the number of arguments. (defn call-fn [class method n-args] (let [o(gensym) args (repeatedly n-args gensym) [class method] (map symbol [class method])] (eval `(fn [~o ~@args] (. ~(with-meta o {

Re: How to invoke java method obtained using clojure.reflect

2013-02-12 Thread AtKaaZ
wow that's pretty epic! => (def f (call-fn "java.lang.String" "substring" "startpos" "endpos")) #'runtime.q/f => (f "abcdef" 2 4) "cd" => (f (str "123" "45") (+ 1 1) 4) "34" Thank you Meikel On Tue, Feb 12, 2013 at 1:51 PM, Meikel Brandmeyer (kotarak) wrote: > Hi, > > if you want to resort

Re: How to invoke java method obtained using clojure.reflect

2013-02-12 Thread Meikel Brandmeyer (kotarak)
Hi, if you want to resort to eval you can define your own function on the fly. (defn call-fn [& args] {:arglists ([class method & args])} (let [o (gensym) [class method & args] (map symbol args)] (eval `(fn [~o ~@args] (. ~(with-meta o {:tag class}) (~

Re: How to invoke java method obtained using clojure.reflect

2013-02-12 Thread AtKaaZ
seems similar to this concept with "new": =>* (new java.lang.RuntimeException "msg")* ;works this way # => *(def a java.lang.RuntimeException)* #'runtime.q/a => *a* java.lang.RuntimeException => *(new a "msg")* ;nope CompilerException java.lang.IllegalArgumentException: Unable to resolve classnam

Re: How to invoke java method obtained using clojure.reflect

2013-02-11 Thread juan.facorro
Since a macro's arguments must be available at compile time, creating one for calling a runtime defined method won't work. Because of this we are left with *eval*, which actually compiles and then evaluates at runtime the expression it receives as an argument. Here's a function that receives an

How to invoke java method obtained using clojure.reflect

2013-02-11 Thread Pablo Nussembaum
Hey all, I'm a newbie that is trying to use clojure for my university grade thesis. In our project we have to generate a graph structure invoking some methods on a standard java class. This class is provided at run time, so the methods that need to be called must be obtained by reflection. I've