在 Scala REPL 中导入多个包
在 Scala 中,我经常需要导入多个包含隐式和其他实用程序的包,特别是在 REPL 上:
import scala.collection.JavaConversions._
import scala.collection.{mutable => mut}
import com.myapp.db._
import com.orm._
val con = connectDb(...)
...
我知道无法在 Scala 中导入多个包(尽管包对象作用域可以提供一些帮助),但是从 REPL 中又如何呢? ?有没有办法从 REPL 中做到这一点,而无需大量复制和粘贴?我也尝试使用 :load,但是在那里导入/创建的东西也没有被引入到 REPL 的范围中。我注意到 :power 命令确实将内容导入到作用域中。
更新::load
实际上确实工作。
In Scala, I frequently have to import multiple packages worth of implicits and other utilities, particularly on the REPL:
import scala.collection.JavaConversions._
import scala.collection.{mutable => mut}
import com.myapp.db._
import com.orm._
val con = connectDb(...)
...
I understand there's no way to import multiple packages in Scala (though package object scopes can help a bit), but what about from the REPL? Is there any way to do this from the REPL without lots of copying and pasting? I also tried using :load, but things imported/created there don't get introduced into the REPL's scope either. I noticed that the :power command does import things into scope.
Update: :load
actually does work.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不确定通用的解决方案,但在 SBT 中可以配置项目,以便控制台 (REPL) 在启动时运行一些初始命令。以下是示例
build.sbt
文件的摘录,编辑:另一个参考是Scalala 项目。他们有一个 Scala 程序,它启动嵌入式 REPL 并填充在必要的进口中。有关使用方法,请参阅他们的快速入门指南。
I'm not sure of a general solution, but in SBT it's possible to configure the project so that the console (REPL) runs some initial commands upon launching. Here's an excerpt from an example
build.sbt
file,Edit: Another reference is the Scalala project. They have a Scala program that launches an embedded REPL and fills in the necessary imports. For usage, see their quick-start guide.