Object runCode(String theCode) { return clojureLoadString.invoke(theCode); }
public List<Object> values () { try { return (List<Object>)map.invoke(readString, combinedResponse().get("value")); } catch (Exception e) { throw new RuntimeException(e); } }
import clojure.lang.RT; import clojure.lang.Var; import clojure.lang.Compiler; import java.io.StringReader; public class Foo { public static void main(String[] args) throws Exception { // Load the Clojure script -- as a side effect this initializes the runtime. String str = "(ns user) (defn foo [a b] (str a \" \" b))"; //RT.loadResourceScript("foo.clj"); Compiler.load(new StringReader(str)); // Get a reference to the foo function. Var foo = RT.var("user", "foo"); // Call it! Object result = foo.invoke("Hi", "there"); System.out.println(result); } }
public Response send (String... kvs) { try { Map msg = PersistentHashMap.createWithCheck(kvs); return new Response((ISeq)message.invoke(client, msg)); } catch (Exception e) { throw new RuntimeException(e); } }
public static void main(String[] args) { REQUIRE.invoke(CLOJURE_MAIN); MAIN.applyTo(RT.seq(args)); } }
private void addImportPathToShell(ImportPath s) { ClassLoader oldLoader = Thread.currentThread().getContextClassLoader(); Thread.currentThread().setContextClassLoader(loader); String ss = s.asString(); if (!ss.isEmpty()) { try { loader.loadClass(ss); clojureLoadString.invoke(String.format("(import '%s)", ss)); } catch (ClassNotFoundException e) { throw new RuntimeException("Could not create class while loading notebook: " + ss); } finally { Thread.currentThread().setContextClassLoader(oldLoader); } } }
@Override protected void doResetEnvironment() { init(); ClassLoader oldLoader = Thread.currentThread().getContextClassLoader(); Thread.currentThread().setContextClassLoader(loader); for (ImportPath s : imports.getImportPaths()) { addImportPathToShell(s); } for (String s : requirements) { if (s != null && !s.isEmpty()) try { clojureLoadString.invoke(String.format("(require '%s)", s)); } catch (Exception e) { logger.error(e.getMessage()); } } Thread.currentThread().setContextClassLoader(oldLoader); executorService.shutdown(); executorService = Executors.newSingleThreadExecutor(); }
private AutocompleteResult autocomplete(String code, int caretPosition, Var clojureLoadString, String shellId) { int i = caretPosition; while (i > 0) { char c = code.charAt(i - 1); if (!Character.isUnicodeIdentifierStart(c) || "[]{}()/\\".indexOf(c) >= 0) { break; } else { i--; } } String _code = code.substring(i, caretPosition); String apropos = "(repl_%1$s/apropos \"%2$s\")"; Object o = clojureLoadString.invoke(String.format(apropos, shellId, _code)); List<String> result = new ArrayList<String>(); for (Object s : ((Collection) o)) { String whole = s.toString(); int d = whole.indexOf('/'); if (d > 0) { String woNS = whole.substring(d + 1); String ns = whole.substring(0, d); result.add(woNS); String currenClojureNS = String.format("%1$s_%2$s", beaker_clojure_ns, shellId); if (!currenClojureNS.equals(ns) && !"clojure.core".equals(ns)) result.add(whole); } else { result.add(whole); } } return new AutocompleteResult(result, i); }
public static void main (String[] args) throws Exception { RT.var("clojure.core", "require").invoke(Symbol.intern("clojure.tools.nrepl.cmdline")); RT.var("clojure.tools.nrepl.cmdline", "-main").applyTo(RT.seq(args)); } }
public static Object invokeTest(Var testVar) { Object o=INVOKE_TEST.invoke(testVar); return o; } }
static void addAnnotation(Object visitor, IPersistentMap meta){ if(meta != null && ADD_ANNOTATIONS.isBound()) ADD_ANNOTATIONS.invoke(visitor, meta); }
@Override public void require(String... namespaces) { ClassLoader origLoader = preInvoke(); try { for (String ns : namespaces) { this.require.invoke(Symbol.create(ns)); } } finally { postInvoke(origLoader); } }