可能重复:
将 Scala 文件加载到解释器中以使用函数?
我像这样启动 sbt 控制台:
alex@alex-K43U:~/projects$ sbt console
[info] Set current project to default-8aceda (in build file:/home/alex/projects/)
[info] Starting scala interpreter...
[info]
Welcome to Scala version 2.9.2 (OpenJDK Client VM, Java 1.6.0_24).
Type in expressions to have them evaluated.
Type :help for more information.
scala>
我有一个test.scala
(/home/alex/projects/test.scala) 文件,其中包含以下内容:
def timesTwo(i: Int): Int = {
println("hello world")
i * 2
}
如何做到这一点,以便我可以在控制台中做这样的事情:
scala> timesTwo
并输出函数的值?