Methods containing bang doesn't work in REPL

岁酱吖の 提交于 2019-12-11 01:19:50

问题


I am running Scala 2.9.2 REPL and if I copy&paste following method:

  def isPrime(num: Int): Boolean = {
    val ceiling = math.sqrt(num.toDouble).toInt
    (2 to ceiling) forall (x => num % x != 0)
  }

..from the file with a source code (where it works well) to the Interactive Interpreter. I get this exception:

java.lang.IllegalArgumentException: != 0): event not found
   at jline.console.ConsoleReader.expandEvents(ConsoleReader.java:426) 
   ...

The problem is the ! character (methods without exclamation mark works well).

Is there any way to make the method work in the REPL?


回答1:


You might have missed this instance:

https://issues.scala-lang.org/browse/SI-7650

But the paulp fix isn't backward compatible.

scala> :power
** Power User mode enabled - BEEP WHIR GYVE **
** :phase has been set to 'typer'.          **
** scala.tools.nsc._ has been imported      **
** global._, definitions._ also imported    **
** Try  :help, :vals, power.<tab>           **

scala> $r.r.in.asInstanceOf[scala.tools.nsc.interpreter.JLineReader].consoleReader.setExpandEvents(false)

scala> 1 != 2
res1: Boolean = true

as opposed to crashing on 2.11:

scala> 1 != 2
java.lang.IllegalArgumentException: != 2: event not found



回答2:


I wasn't able to overcome this issue with the original installation, but installing new version of Scala helped. Perhaps, it is issue of Fedora 17 rpm Scala package.

  • Related bug
  • rpm package with "broken" REPL


来源:https://stackoverflow.com/questions/17630511/methods-containing-bang-doesnt-work-in-repl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!