On 18 October 2015 at 23:54, Timur <timurha...@gmail.com> wrote:

> Hi all,
>
> Is there anyway to call an object member using its symbol?
>
> For instance we have an object o, we get the symbol of a method, e.g.,
> toString, of our object o using clojure.reflect/reflect and and I want to
> execute this method on this object through the symbol.
>
> For instance *(. obj sym)* throws an exception. Here symbol for instance
> contains toString
>
> Any ideas about how I can do this?
>

eval is probably the most straightforward way to achieve this:

    (eval `(. ~obj ~sym))

I'm uncertain of the performance of this compared to using the Java
reflection API, but it's a lot easier to write.

- James

-- 
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 - please be patient with your 
first post.
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
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to