Created
April 14, 2014 13:18
-
-
Save dannypurcell/10647015 to your computer and use it in GitHub Desktop.
Example Java static for calling Clojure functions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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