Cool... that looks like it got me past the 'method-as-a-string' problem, but
now I'm getting errors with not finding a matching method on the class by
that name. I'm guessing that this means there was a problem matching the
type signature of the method.

The arguments to the method are stored in a 'clojure.lang.PersistentVector',
and if I duplicate the method I'm trying to access but set the only
parameter to be typed as 'clojure.lang.PersistentVector', then it works. The
new method with the new type signature works. Which to me means that we're
passing all the arguments to the method still inside their original vector -
right?

I guess I'm still stuck on how to expand the vector of arguments in place...
and I'm really not very sure what you're doing with the '&' in the
parameters for the str-invoke. Is that a way of slurping all the remaining
parameters into a vector? If so, then aren't I needing to do the opposite?

I tried removing the &, and into-array - that didn't work. I tried changing
the method into a macro so I could splice in the vector of args - that
didn't work. This is getting frustrating. Everything else has been so
relatively easy to do until now.

I really appreciate your help in walking me through my lack of
understanding.

If I'm following you correctly I think we're here:

user=> (defn str-invoke [instance method-str & args]
(clojure.lang.Reflector/invokeInstanceMethod instance method-str (into-array
args)))
#'user/str-invoke
user=> (def i "sampleString")
#'user/i
user=> (def m "substring")
#'user/m
user=> (def args [2,3])
#'user/args
user=> (str-invoke i m args)
java.lang.IllegalArgumentException: Unexpected param type (NO_SOURCE_FILE:0)
user=> (str-invoke i m 2 3)
"m"
user=>

-Rich



On Sat, Feb 21, 2009 at 4:19 PM, Timothy Pratley
<timothyprat...@gmail.com>wrote:

>
> How embarrassing!
>
> This works much better:
>
> (defn str-invoke [method-str instance & args]
>  (clojure.lang.Reflector/invokeInstanceMethod instance method-str (to-
> array args)))
>
> (let [ts "toString", ct "compareTo"]
>  (println (str-invoke ts 5))
>  (println (str-invoke ct 5 4))
>  (println (str-invoke ct 5 5)))
>
> ie: this is just using reflection as pmf suggested, however I think
> this form is more convenient as Clojure's Reflector class does all the
> hard work of matching the parameters for you. I'm sure someone will
> post a macro solution, but hopefully this will do till then.
>
>
> 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