Hi guys, I’m trying to call Clojure from Java(I already managed to do it compiling Clojure using :gen-class ).
I want call Clojure using Java without compiling Clojure… I’m having issues with my structs they are not behaving in the way that I want, I tested the Clojure code on REPL and it seems to be ok... I Guess is something that I’m doing in java(possibly wrong ) [company.clj] (ns user) (def employees (ref [])) (defstruct employee :name :age :role :salary) (defn hire[e] (dosync (alter employees conj e)) ) (defn print-employee[e] (prn (str "Name: " (:name e) " - Age: " (:age e) " - Role: " (:role e) " - Salary:" (:salary e) ) ) ) (defn print-employees[] (for [i (range (count @employees))] (print-employee (employees i)) ) ) [JavaCallsClojureInterpreted.java] import clojure.lang.RT; import clojure.lang.Var; /** * * @author Diego Pacheco * */ public class JavaCallsClojureInterpreted { public static void main(String args[]) throws Throwable{ try{ RT.loadResourceScript("company.clj"); Var struct = RT.var("clojure.core", "struct","employee :diego 10 :coach 1000"); Var hire = RT.var("user", "hire"); Object r = hire.invoke(struct); System.out.println(r); Var printee = RT.var("user", "print-employee"); Object r2 = printee.invoke(struct); System.out.println(r2); Var print = RT.var("user", "print-employees"); Object result = print.invoke(); System.out.println(result); }catch(Exception e){ e.printStackTrace(); } } } This code produce the following output: [#'clojure.core/struct] "Name: - Age: - Role: - Salary:" null "Name: - Age: - Role: - Salary:" clojure.lang.LazySeq@1f Any Clue ? Thanks for your help. Cheers, Diego Pacheco @diego_pacheco -- 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