问题
Looking at this SO post, I tried to paste the following code into Putty and Windows command line.
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)
}
}
However, even though I'm simply pasting into Putty and Windows 7 command line, the following gets output:
scala> :paste // Entering paste mode (ctrl-D to finish)
def size(root: Leaf, left: Branch, right: Branch) : Int = { def go(branch: Branch, acc: Int) : Int = branch match { case Nil => acc
=:= AnyRef ArrowAssoc Class ClassManifest Downloads
DummyImplicit Ensuring Function
Manifest Map NoManifest OptManifest Pair Set
String Triple root
arrayToCharSequence asInstanceOf assert
assume augmentString bin ch
classManifest classOf com
It's not compiling due to, I believe, this unexpected output behavior when I try to paste.
回答1:
Check whether there are TAB characters in there. sbt triggers code completion when you press TAB. It does it also in paste mode. So it might have tried to complete your statement and completed it wrong.
来源:https://stackoverflow.com/questions/18222272/pasting-into-repl-with-paste