是否有可下载的Jar用于Frege JSR223集成?

时间:2013-09-27 23:24:40

标签: frege

github上的frege脚本项目包含JSR223所需的ScriptEngineFactory,但看起来它既没有打包在Frege语言jar本身,也没有打包在REPL或其任何依赖项中。

在某处有这样的罐子还是需要额外的构建?

1 个答案:

答案 0 :(得分:2)

现在可以从here下载Frege的JSR 223实现。这是一个演示Frege脚本引擎的小程序。

import javax.script.Compilable;
import javax.script.CompiledScript;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import java.math.BigInteger;

public class FregeScriptEngineTest {

    public static void main(final String[] args) throws Exception {
        //Get the Frege Script Engine
        final ScriptEngineManager factory = new ScriptEngineManager();
        final ScriptEngine engine = factory.getEngineByName("frege");

        //Evaluate an expression
        System.out.println(engine.eval("show $ take 10 [2,4..]"));

        //Bind a value
        engine.eval("x=5");
        System.out.println(engine.eval("x"));

        //Pass some objects from host to scripting environment
        engine.put("foo::String", "I am foo");
        engine.put("bar::Integer", new BigInteger("1234567890123456789"));

        //Use the objects from host environment
        System.out.println(engine.eval("\"Hello World, \" ++ foo"));
        System.out.println(engine.eval("bar + big 5"));

        /*
         * Frege Script Engine is `Compilable` too. So scripts can be compiled
         * and then executed later.
         */
        final Compilable compilableEngine = (Compilable) engine;
        final CompiledScript compiled =
                compilableEngine.compile("fib = 0 : 1 : zipWith (+) fib fib.tail");
        compiled.eval(); //Evaluate the compiled script
        //use compiled script
        System.out.println(engine.eval("show $ take 6 fib"));
    }

}

输出:

[2, 4, 6, 8, 10, 12, 14, 16, 18, 20]
5
Hello World, I am foo
1234567890123456794
[0, 1, 1, 2, 3, 5]