I think the following is “looked down upon” or “discouraged“, but I managed to sift through how clojure itself handles its own stuff in java and I came up with the following.
Say, that you want to set *out*, *in*, and *err* in clojure to something from Java before starting a REPL. Here is how I passed on these values to the clojure RT: try { Var.pushThreadBindings(RT.map( RT.OUT, new OutputStreamWriter(MYout), RT.IN, new LineNumberingPushbackReader(new InputStreamReader(MYin)), RT.ERR, new PrintWriter(new OutputStreamWriter(MYout), true))); main.main(new String[] {"-r"}); } catch (Exception e) {} finally { Var.popThreadBindings(); } Don’t forget to import (after setting clojure.jar on the cp). import clojure.main; import clojure.lang.RT; import clojure.lang.Var; Note that the doc-string of the clojure (repl function allows for hooks for some of what you want. You just need to look into how you could pass on those functions for :need- prompt, :prompt, :flush, :read in a way that clojure can digest, which I think is just a Runnable in a map of sorts. But you’ll have to look into that to be sure. Regardless, I highly recommend that you separate Java from clojure coding as mush as possible, or at least treat clojure in a functional way when touching it from Java. I hope this helps. If someone else has a better way, I’m all ears. On Dec 7, 8:19 am, Mike <cki...@gmail.com> wrote: > I've seen an example of launching a Clojure script from Java (http:// > en.wikibooks.org/wiki/Clojure_Programming/ > Tutorials_and_Tips#Invoking_Clojure_from_Java), but I've got an > application in which I'd like to run a REPL. > > My app has its own JPanel for display results, and a text area for > input, so I'll need to start repl with some replacement callback > functions (read, print, prompt, need-prompt). I'd like to code as > much as possible in Clojure, but at some point I need to pass in some > Java object instances that my wrapper functions will use to perform I/ > O for the repl. > > Has anyone done this recently? Could someone point me in the right > direction for exposing Java objects into Clojure? I've tried reading > main.java and RT.java looking for hints, but I'm not too smart yet > about the Clojure environment, the scope of when things live, and > such. > > Thanks in advance for any hints... > Mike -- 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