Created
June 28, 2013 06:14
-
-
Save mmhelloworld/5882797 to your computer and use it in GitHub Desktop.
JSR 223 - Scripting support for Frege
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package helloworld; | |
import javax.script.Compilable; | |
import javax.script.CompiledScript; | |
import javax.script.ScriptEngine; | |
import javax.script.ScriptEngineManager; | |
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..]")); | |
//Pass some objects from host to scripting environment | |
engine.put("foo::String", "Foo"); | |
engine.put("bar::Integer", new java.math.BigInteger("12234234232322")); | |
//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 | |
System.out.println(engine.eval("show $ take 6 fib")); //use compiled script | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment