A new error occurred in Clojure 1.5.0.
 
(Java interop: Compiler.load(new StringReader(str));)
 
# Code #
import java.io.IOException;
import java.io.StringReader;
import clojure.lang.Compiler;
import clojure.lang.RT;
import clojure.lang.Var;
public class Main {
    public static void main(String[] args) throws IOException, 
ClassNotFoundException {        
        //clojure.main.main(args);
        
        // Load the Clojure script -- as a side effect this initializes the 
runtime.
        String str = "(ns user) (defn foo [a b]   (str a \" \" b)) (def a 
3)";
        //RT.loadResourceScript("foo.clj");
        Compiler.load(new StringReader(str));
        // Get a reference to the foo function.
        Var foo = RT.var("user", "foo");
        Var a = RT.var("user", "a"); // reference to the variable a
        // Call it!
        Object result = foo.invoke("Hi", "there");
        System.out.println(result);
        
        System.out.println(a);
        System.out.println(a.get());
    }
}
 
Test code: 
*https://bitbucket.org/ktg/clojureembedtest*<https://bitbucket.org/ktg/clojureembedtest>(Eclipse
 project)

Reference: *
http://stackoverflow.com/questions/2181774/calling-clojure-from-java*<http://stackoverflow.com/questions/2181774/calling-clojure-from-java>
 
 
$ java -version
java version "1.7.0_15"
OpenJDK Runtime Environment (IcedTea7 2.3.7) (7u15-2.3.7-0ubuntu1~12.04.1)
OpenJDK Client VM (build 23.7-b01, mixed mode, sharing)
$ java -cp clojure-1.5.0.jar:. Main

Exception in thread "main" java.lang.ExceptionInInitializerError
at clojure.lang.Compiler.<clinit>(Compiler.java:47)
at Main.main(Main.java:16)
Caused by: java.lang.NullPointerException
at clojure.lang.RT.baseLoader(RT.java:2043)
at clojure.lang.RT.load(RT.java:417)
at clojure.lang.RT.load(RT.java:411)
at clojure.lang.RT.doInit(RT.java:447)
at clojure.lang.RT.<clinit>(RT.java:329)
... 2 more
$ java -cp clojure-1.4.0.jar:. Main

Hi there
#'user/a
3
 
 

-- 
-- 
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
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to