I have a java class with several static methods:

package org.domain.test;

public class My {
  static public void sBar(String x, String y)
{ System.out.println("sBar "+x+":"+y); }
  static public void sBaz(String x, String y)
{ System.out.println("sBaz "+x+":"+y); }
}

I'd like to execute these methods from clojure. The concrete method
will be specified at runtime.

test.clj:
(ns test)
(:import org.domain.test.My)

; this is what I need but it does not work:
(defn foo [f x y]
   (. org.domain.test.My sBar x y)         ;hard coded call of the
java static method sBar
  ;(. org.domain.test.My f x y))           ;compiler error
  ;(map #(. org.domain.test.My % x y) [f]) ;compiler error
  ;(apply (. org.domain.test.My f x y))    ;compiler error
  ;(. org.domain.test.My #(f) x y)         ;compiler error
  )

; this works but it's ugly:
(defn bar [f x y]
  (let [s (str "(. org.domain.test.My " f " "     ; method sBar or
sBaz
                                   "\"" x "\" "   ; String x
                                   "\"" y "\")")] ; String y
    (load-string s)))


; the actual call on the REPL is quite ugly and (I believe) also quite
inefficient and error-prone:
(bar "sBaz" "aaa" "bbb")

Do you know how to write the foo function without using load-string?
Thx in advance!

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

Reply via email to