Skip to content

Instantly share code, notes, and snippets.

@Dierk
Created October 7, 2013 11:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Dierk/6866380 to your computer and use it in GitHub Desktop.
Save Dierk/6866380 to your computer and use it in GitHub Desktop.
call frege from groovy via jsr223 integration
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