:imports 1) import scala.Pre-6ren">
gpt4 book ai didi

scala - 如何从命令行向 REPL 添加导入?

转载 作者:行者123 更新时间:2023-12-01 11:42:22 25 4
gpt4 key购买 nike

如何让 REPL 导入命令行中给定的包?

示例:

scala -someMagicHere "import sys.error"
scala> :imports
1) import scala.Predef._ (162 terms, 78 are implicit)
2) import sys.error (2 terms)

scala> _

PS:它不是重复的。我想要自动化解决方案,而不是每次运行 REPL 时都手动粘贴一些代码。此外,我不想仅在 REPL 启动后使用 SBT 来运行一个命令。

最佳答案

将其粘贴到文件中。

apm@mara:~/tmp$ scala -i imports.script
Loading imports.script...
import sys.error

Welcome to Scala version 2.10.2 (OpenJDK 64-Bit Server VM, Java 1.7.0_25).
Type in expressions to have them evaluated.
Type :help for more information.

scala> :impo
1) import scala.Predef._ (162 terms, 78 are implicit)
2) import sys.error (2 terms)

编辑:

我认为您会因发现或以其他方式引发或诱发错误而获得奖励积分:

apm@mara:~/tmp$ scala -e "import sys.error"
java.lang.ClassNotFoundException: Main

关于scala - 如何从命令行向 REPL 添加导入?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18509116/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com