mth / yeti

Functional programming language for JVM.
http://mth.github.io/yeti/
Other
246 stars 16 forks source link

Script Engine Support #10

Open sirinath opened 10 years ago

sirinath commented 10 years ago

Can this be used as a Java Script Engine? If not can this be added?

mth commented 10 years ago

Probably the support can be added (I don't know any reason, why this shouldn't be possible). You could write and submit the code. :)

sirinath commented 10 years ago

I might be a user of of this in calling using some ML code from Java but for implementing a scripting engine I am not the best person.

mth commented 10 years ago

On Tue, 3 Dec 2013, Suminda Dharmasena wrote:

I might be a user of of this in calling using some ML code from Java but for implementing a scripting engine I am not the best person.

You can use the compiler from Java quite easily without scripting engine.

Only a thin wrapper class written in Yeti is needed, that calls evaluateYetiCode, and then you can use the wrapper from Java. Simple example would be:

module evalwrapper;

load yeti.lang.compiler.eval;

class EvalYetiCode ctx = evaluateYetiCode [],

 Object eval(String code)
     result = ctx [] code;
     case result.result of
     Result res: res;
     Exception ex: throw ex;
     _: failWith result.str;
     esac

end

It could be used for example with following Java code:

public class TestEval { public static void main(String[] _) { new EvalYetiCode().eval("println 'Hello world'"); } }

The code could be compiled and run with following commands:

java -jar yeti.jar -d . evalwrapper.yeti javac TestEval.java java -cp yeti.jar:. TestEval

The evaluateYetiCode documentation:

http://dot.planet.ee/yeti/docs/latest/yeti.lang.compiler.eval.html#evaluateYetiCode

sirinath commented 10 years ago

Thanks. This is good enough for now.

In case anybody want to take the next step with this feature request this might help: https://today.java.net/pub/a/today/2006/09/21/making-scripting-languages-jsr-223-aware.html