我将解释什么,我通过限制范围首先意味着:是否有可能在Scala中创建一个“受限范围”?
restrictedScope (allowedNamespace) {
/* THE CLIENT CODE GOES HERE */
/* the namespace in this closure is limited only to the idioms
I allow, both in terms of reserved words and standard functions */
val result = allowedNamespace.run(); // works, since run() ...
// ... is a function of allowedNamespace
val list = new List(); // does not work, since List is not in scope
/* CLIENT CODE SAMPLE (prepare, release and wait are defined in allowedNamespace) */
prepare("service 1")
wait(1000)
release("service 1")
...
}
在执行基于常规的Scala代码严格势在必行DSL,我想安全地运行客户端代码。为了安全起见,我可能想要限制这样的构造的使用,如和,如果(只有可能的话),删除列表的创建,并且只允许我在允许的命名空间中定义的习语被执行/引用。
是否有设施可以做到这一点,而不会覆盖所有标准成语?
如果没有,是否有自动方式(可能通过反射)来覆盖导入到命名空间的所有标准成语?
我想这就是他们所说的一流的上下文,但我不确定。 – missingfaktor 2012-04-28 13:48:28