Calling clojure from java

前端 未结 9 1506
梦毁少年i
梦毁少年i 2020-11-22 11:13

Most of the top google hits for \"calling clojure from java\" are outdated and recommend using clojure.lang.RT to compile the source code. Could you help with a

9条回答
  •  执笔经年
    2020-11-22 11:38

    This works with Clojure 1.5.0:

    public class CljTest {
        public static Object evalClj(String a) {
            return clojure.lang.Compiler.load(new java.io.StringReader(a));
        }
    
        public static void main(String[] args) {
            new clojure.lang.RT(); // needed since 1.5.0        
            System.out.println(evalClj("(+ 1 2)"));
        }
    }
    

提交回复
热议问题