Created
October 7, 2013 11:33
-
-
Save Dierk/6866380 to your computer and use it in GitHub Desktop.
call frege from groovy via jsr223 integration
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 com.canoo | |
import javax.script.* | |
//Get the Frege Script Engine | |
final frege = new ScriptEngineManager().getEngineByName("frege") | |
//Evaluate an expression | |
println frege.eval('show $ take 10 [2,4..]') | |
//Bind a value | |
frege.eval "x=5" | |
println frege.eval("x") | |
//Pass some objects from host to scripting environment | |
frege.put "foo::String", "I am foo" | |
frege.put "bar::Integer", 1234567890123456789g | |
//Use the objects from host environment | |
println frege.eval('"Hello World, " ++ foo') | |
println frege.eval("bar + big 5") | |
/* | |
* Frege Script Engine is `Compilable` too. So scripts can be compiled | |
* and then executed later. | |
*/ | |
final compiled = frege.compile("fib = 0 : 1 : zipWith (+) fib fib.tail") | |
compiled.eval() //Evaluate the compiled script | |
//use compiled script | |
println frege.eval('show $ take 6 fib') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment