ILoop
工作?据我所知,这并不比以下操作复杂:// insert the code below wherever you want a REPL
val repl = new ILoop
repl.settings = new Settings
repl.in = SimpleReader()
repl.createInterpreter()
// bind any local variables that you want to have access to
repl.intp.bind("i", "Int", i)
repl.intp.bind("e", "Exception", e)
// start the interpreter and then close it after you :quit
repl.loop()
repl.closeInterpreter()
breakIf
API 相比,这种方法消除了对两个级别的间接性,即对 if
条件(其被包装为 => 布尔值
)和 DebugParam
/NamedParam
(它们是临时包装器,仅用于填充 bind
参数)。
这种方法还允许您根据需要指定您的 Settings
。例如,一些 REPL 错误可以通过 -Yrepl-sync
解决,但 break
并没有提供指定该选项的方式。
ILoop.settings
和 ILoop.in
设置一些更好的默认值将使上述代码更加易读。我对 createInterpreter
、bind
、loop
或 closeInterpreter
的调用并不感到困扰,因为这正是我们想要实现的。但是,在 ILoop 上设置变量似乎不太合适。 - Steverepl.settings.Yreplsync.value = true
。 - Ben Hutchison