从脚本启用REPL power user mode(:power)

时间:2012-09-23 11:01:54

标签: scala interpreter read-eval-print-loop

我正在尝试将字符串动态解释为Scala中的命令。为此,根据我的理解,我需要在处于电源模式时调用intp.interpret("string")(其中intp代表当前解释器而string代表我的命令),对吧?

但是,我的问题是我想从脚本中做到这一点。因此,我正在寻找一种从脚本内部切换到超级用户模式的方法,然后调用intp.interpret。

有没有办法从脚本文件内部切换?

1 个答案:

答案 0 :(得分:2)

如果您从bash脚本中调用REPL或某些东西,那么您可以通过:power系统属性立即启用scala.repl.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>