为什么不;相当于eol?

Why does not ; equivalent to the eol?

这是 the code that compiles 的预期

  def coarse_grained: Int = {
    def fib: Int = List(1,2) sum ;
    fib
  }

one which does not

  def coarse_grained: Int = {
    def fib: Int = List(1,2) sum
    fib
  }

唯一的区别是sum之后的;

大家知道,List(2,6,9).drop(1)也可以写成List(2,6,9) drop 1。其实也可以这样写

List(2,6,9) drop
1

编译器一直在寻找最后的参数,甚至超过换行符。所以如果你想像这样 List(1,2) sum 这样 List(1,2).sum ,你需要使用分号 ; 来告诉编译器停止寻找最后的参数。不来了。