在C#中重新IronScheme引擎 [英] Resetting IronScheme Engine in C#

查看:186
本文介绍了在C#中重新IronScheme引擎的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法来重置IronScheme引擎? 我主要目标是确保连续调用string.Eval()是独立地执行。

Is there a way to "reset" the IronScheme engine? I'm essentially aiming to ensure that successive calls to string.Eval() are executed independently.

例如,我想执行

(定义×1.0)(+×5.0)的eval()

然后复位,并有通话

(+ X 3.0)的eval()

如果它是由自己执行的失败,因为它会。

fail as it would if it were executed by itself.

更妙的是一个方法,让每个n并发线程在执行自己的独立空间。

Even better would be a way to give each of n concurrent threads its own independent space in which to execute.

推荐答案

您有2个选项的REPL(与图书馆它甚至不会让你写这样code; P)。

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

1:复位的交互环境

这可与来完成(交互环境(新的交互环境))

示例:

> (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:创建你坚持在C#中的新的交互环境

如果你想并发的环境中,这可能是最好的选择。我用这个方法对于 IronScheme在线评估

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

示例:

"(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();

这篇关于在C#中重新IronScheme引擎的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆