Skip to content

Instantly share code, notes, and snippets.

@dannypurcell
Created April 14, 2014 13:18
Show Gist options
  • Save dannypurcell/10647015 to your computer and use it in GitHub Desktop.
Save dannypurcell/10647015 to your computer and use it in GitHub Desktop.
Example Java static for calling Clojure functions
import clojure.lang.IFn;
import clojure.lang.RT;
public class Clojure {
public static Object invokeCLJ(String ns, String fn, Object... args) throws NoSuchMethodException {
clojure.lang.Compiler.eval(RT.readString("(require '" + ns + " :reload-all)"));
clojure.lang.IFn f = (IFn) RT.var(ns, fn).deref();
if (f == null) {
throw new NoSuchMethodException("Could not find " + fn + " in " + ns + " or could not load " + ns);
}
return f.applyTo(RT.arrayToList(args));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment