If i were doing same thing I would put all necessary initalization
into a Clojure script and wrapped necessary functions to have less
arguments to pass from Java.
This way later you'll need to load single script only. Say
(ns
(use lobos.core))
(def db {.....})
(defn create2 [table-name] (create db (table table-name)))
This might not be convenient in your case however.
--
Petr Gladkikh
Am 26.07.2011 um 19:48 schrieb mmwaikar:
> RT.load("lobos/core", true);
> RT.load("lobos/schema", true);
You should go through require.invoke(). Not RT.load().
> and called wrapper.createTable() then I get - (#<core$create_STAR_ lobos.core$create_STAR_@49431028> (quote {:classname "org.postgresql.Driver", :subprotocol "postgresql", :user "postgres", :password "lindb2011", :subname "//localhost:5432/flyway"}))
>
> I really don't understand the output, but it is definitely not what I am expecting.
create is obviously also a macro. You'll have to use create*.
Sincerely
Meikel
Am 28.07.2011 um 19:43 schrieb mmwaikar:
> Thanks again Meikel. Where can I read about things like bindRoot, intern or to be precise java-clojure interop?
There are only a few things you must know:
- RT.var to get a variable from a namespace
- v.invoke to invoke a function stored in a Var
That's it. Then do the normal clojure stuff. bindRoot, intern and such are none of our concerns. (I don't know anything about them, either.)
So to load a namespace, you would say in Clojure:
(require 'some.name.space)
In Java, you to the same with more boilerplate:
RT.var("clojure.core", "require").invoke(RT.var("clojure.core", "symbol").invoke("some.name.space"))
This is my last information on how the officially blessed way to interface with Clojure from Java looks like. I'm not sure about RT.map.
If the thing you want to call is a macro, you have to hope that the library other provided the logic as star function (as in Nicolas' case). If there is no function containing the actual logic, you have to re-implement the macro in Java. cf. http://stackoverflow.com/questions/6672934/how-to-call-clojure-macros-from-java/6674923#6674923
Sincerely
Meikel
There's also the eval(read(whatever)) route, if you need to resort to it.
--
Protege: What is this seething mass of parentheses?!
Master: Your father's Lisp REPL. This is the language of a true
hacker. Not as clumsy or random as C++; a language for a more
civilized age.