我试图动态地将字符串解释为
Scala中的命令.为此,根据我的理解,我需要在处于电源模式时调用intp.interpret(“string”)(其中intp代表当前解释器和我的命令的字符串),对吧?
但是,我的问题是我想从脚本中做到这一点.因此,我正在寻找一种从脚本内部切换到超级用户模式的方法,然后调用intp.interpret.
有没有办法从脚本文件内部切换?
解决方法
如果你是从bash脚本调用REPL,那么你可以通过scala.repl.power系统属性立即启用:power模式,
miles@lewis$scala -Dscala.repl.power Welcome to Scala version 2.9.2 (Java HotSpot(TM) 64-Bit Server VM,Java 1.7.0_05) Type in expressions to have them evaluated. Type :help for more information. scala> [info] compiler init time: 2.186 s. scala> ** Power User mode enabled - BEEP BOOP SPIZ ** ** :phase has been set to 'typer'. ** ** scala.tools.nsc._ has been imported ** ** global._ and definitions._ also imported ** ** Try :help,vals.<tab>,power.<tab> ** scala> [info] total init time: 5.105 s. scala>