0

查看这篇 SO帖子,我尝试将以下代码粘贴到 Putty 和 Windows 命令行中。

def size(root: Leaf, left: Branch, right: Branch) : Int = {
   def go(branch: Branch, acc: Int) : Int = branch match {
       case Nil => acc
       case branch.left != Nil && branch.right != Nil => go(branch.left, acc) + 
                                                          go(branch.right, acc)
       case branch.left != Nil => go(branch.left, acc)
       case branch.right != Nil => go(branch.right, acc)
       case _ => 0
   }
  root match {
    case Nil => go(left, 0) + go(right, 0)
    case _ => 1 + go(left, 0) + go(right, 0)
  }
}

但是,即使我只是粘贴到 Putty 和 Windows 7 命令行中,也会得到以下输出:

scala> :paste // 进入粘贴模式(ctrl-D 完成)

def size(root: Leaf, left: Branch, right: Branch) : Int = { def go(branch: Branch, acc: Int) : Int = branch match { case Nil => acc

=:= AnyRef ArrowAssoc 类 ClassManifest 下载
DummyImplicit Ensuring Function
Manifest Map NoManifest OptManifest Pair Set
String Triple root
arrayToCharSequence asInstanceOf assert
假设 augmentString bin ch classManifest
classOf com

我相信,当我尝试粘贴时,它不会编译,因为这种意外的输出行为。

4

1 回答 1

1

检查那里是否有 TAB 字符。当你按下 TAB 时 sbt 触发代码完成。它也在粘贴模式下进行。所以它可能试图完成你的陈述并错误地完成了它。

于 2013-08-14T08:38:12.867 回答