Resetting IronScheme Engine in C#

空扰寡人 提交于 2019-12-06 01:34:55

You have 2 options for the REPL (with libraries it will not even allow you to write such code ;p).

1: Reset the interaction environment.

This can be done with (interaction-environment (new-interaction-environment)).

Sample:

> (define x 5) (+ x 5)
10
> (interaction-environment (new-interaction-environment))
> (+ x 5)
Unhandled exception during evaluation:
&undefined
&message: "attempted to use undefined symbol"
&irritants: (x)

2: Create a new interaction environment that you hold on to in C#.

If you want to concurrent environments, this is probably the best option. I use this approach for the IronScheme online evaluator.

Sample:

"(define x 1.0) (+ x 5.0)".Eval();
var env = "(new-interaction-environment)".Eval();
"(+ x 3.0)".EvalWithEnvironment(env);

Possible solution:

Func<object> reset = 
   "(lambda () (interaction-environment (new-interaction-environment)))".
   Eval<Callable>().Call;

"(define x 1.0) (+ x 5.0)".Eval();

reset();

"(+ x 5.0)".Eval();
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!