Thanks all for the pointers, this looks like a workable approach.  In my
case I'm not bothered by the performance hit from reflection (CPS
transformation creates an obscene number of anonymous functions anyway).
However I am running into an issue.  Here's my dot function:
(def not-seq? (comp not seq?))

(defn dot [obj member-expr]
  (let [member       (str (first member-expr))
arg-or-args    (rest member-expr)
args             (if (not-seq? arg-or-args)
             [arg-or-args]
             arg-or-args)]
    (Reflector/invokeInstanceMethod obj
    member
    (to-array args))))

This works fine for:

(dot "Hello" (list 'substring 1 2))

But throws an exception for this:

(let [myref (ref {})]
  (dot
   clojure.lang.LockingTransaction
   (list 'runInTransaction (fn [] (commute myref assoc :mykey :myval)))))

I'm getting a instance method not found exception which seems odd. I looked
at LockingTransaction.java and I see that runInTransaction does in fact take
Callable, and fn's are Callable.  Any thoughts?

I knew I would have to really learn Java at some point ;)


On Sun, Mar 22, 2009 at 12:06 PM, Stuart Sierra <the.stuart.sie...@gmail.com
> wrote:

>
> On Mar 21, 10:23 pm, Timothy Pratley <timothyprat...@gmail.com> wrote:
> > You may be able to achieve what you want by directly accessing
> > Clojure's reflector class instead of using the special form:
>
> You could also call Java's reflection API directly.
>
> -Stuart Sierra
> >
>

--~--~---------~--~----~------------~-------~--~----~
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