我想使用 sbt 控制台作为 REPL 来尝试一些 scala 代码。
这就是我启动 sbt 控制台的方式
$ sbt
[info] Loading project definition from /Users/antkong/wd/scala/recfun/project/project
[info] Loading project definition from /Users/antkong/wd/scala/recfun/project
[info] Set current project to progfun-recfun (in build file:/Users/antkong/wd/scala/recfun/)
> console
[info] Compiling 2 Scala sources to /Users/antkong/wd/scala/recfun/target/scala-2.10/classes...
[info] 'compiler-interface' not yet compiled for Scala 2.10.1. Compiling...
[info] Compilation completed in 22.682 s
[info] Starting scala interpreter...
[info]
然后我输入了这段代码:
def sq(x:Int)=>x*x
我预计这是一个有效的 scala 代码片段。所以我不明白为什么 sbt 会抛出这个错误信息:
scala> def sq(x:Int)=> x*x
<console>:1: error: '=' expected but '=>' found.
def sq(x:Int)=> x*x
^
它是语法问题还是只是 sbt 控制台/scala 解释器的行为?