Search in sources :

Example 21 with IFn

use of clojure.lang.IFn in project enumerable by hraberg.

the class JavaScriptTest method interactingWithClojure.

@Test
public void interactingWithClojure() throws Exception {
    IFn star = (IFn) ClojureTest.getClojureEngine().eval("*");
    FunctionFn2 f = toFunction(LambdaClojure.toFn2(star));
    js.put("f", f);
    assertEquals(6.0, js.eval("f(2, 3)"));
}
Also used : IFn(clojure.lang.IFn) FunctionFn2(org.enumerable.lambda.support.javascript.LambdaJavaScript.FunctionFn2) GroovyTest(org.enumerable.lambda.support.groovy.GroovyTest) ScalaTest(org.enumerable.lambda.support.scala.ScalaTest) JRubyTest(org.enumerable.lambda.support.jruby.JRubyTest) Test(org.junit.Test) ClojureTest(org.enumerable.lambda.support.clojure.ClojureTest)

Example 22 with IFn

use of clojure.lang.IFn in project storm by nathanmarz.

the class ClojureSpout method open.

@Override
public void open(final Map conf, final TopologyContext context, final SpoutOutputCollector collector) {
    IFn hof = Utils.loadClojureFn(_fnSpec.get(0), _fnSpec.get(1));
    try {
        IFn preparer = (IFn) hof.applyTo(RT.seq(_params));
        final Map<Keyword, Object> collectorMap = new PersistentArrayMap(new Object[] { Keyword.intern(Symbol.create("output-collector")), collector, Keyword.intern(Symbol.create("context")), context });
        List<Object> args = new ArrayList<Object>() {

            {
                add(conf);
                add(context);
                add(collectorMap);
            }
        };
        _spout = (ISpout) preparer.applyTo(RT.seq(args));
        //this is kind of unnecessary for clojure
        try {
            _spout.open(conf, context, collector);
        } catch (AbstractMethodError ame) {
        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : IFn(clojure.lang.IFn) PersistentArrayMap(clojure.lang.PersistentArrayMap) Keyword(clojure.lang.Keyword) ArrayList(java.util.ArrayList)

Example 23 with IFn

use of clojure.lang.IFn in project CorfuDB by CorfuDB.

the class ShellMain method main.

public static void main(String[] args) {
    IFn require = Clojure.var("clojure.core", "require");
    require.invoke(Clojure.read("org.corfudb.shell"));
    IFn shell = Clojure.var("org.corfudb.shell", "-main");
    shell.invoke(args);
}
Also used : IFn(clojure.lang.IFn)

Aggregations

IFn (clojure.lang.IFn)23 Test (org.junit.Test)16 GroovyTest (org.enumerable.lambda.support.groovy.GroovyTest)15 JavaScriptTest (org.enumerable.lambda.support.javascript.JavaScriptTest)15 JRubyTest (org.enumerable.lambda.support.jruby.JRubyTest)15 ScalaTest (org.enumerable.lambda.support.scala.ScalaTest)15 Keyword (clojure.lang.Keyword)6 PersistentArrayMap (clojure.lang.PersistentArrayMap)6 ArrayList (java.util.ArrayList)6 ClojureTest (org.enumerable.lambda.support.clojure.ClojureTest)4 ScriptEngine (javax.script.ScriptEngine)3 RubyProc (org.jruby.RubyProc)2 APersistentVector (clojure.lang.APersistentVector)1 IPersistentMap (clojure.lang.IPersistentMap)1 IPersistentVector (clojure.lang.IPersistentVector)1 ISeq (clojure.lang.ISeq)1 Closure (groovy.lang.Closure)1 FunctionFn2 (org.enumerable.lambda.support.javascript.LambdaJavaScript.FunctionFn2)1 LambdaJRuby (org.enumerable.lambda.support.jruby.LambdaJRuby)1 ScalaInterpreter (org.enumerable.lambda.support.scala.ScalaTest.ScalaInterpreter)1