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 -
seems similar to this concept with new:
=* (new java.lang.RuntimeException msg)* ;works this way
#RuntimeException java.lang.RuntimeException: msg
= *(def a java.lang.RuntimeException)*
#'runtime.q/a
= *a*
java.lang.RuntimeException
= *(new a msg)* ;nope
CompilerException
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})
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)
m...@kotka.dewrote:
Hi,
if you want to resort to eval
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
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 args] (map
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
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
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
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
10 matches
Mail list logo