Jiri Kremser
Jiri Kremser

Reputation: 12837

Methods containing bang doesn't work in REPL

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?

Upvotes: 2

Views: 158

Answers (2)

som-snytt
som-snytt

Reputation: 39577

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

Upvotes: 1

Jiri Kremser
Jiri Kremser

Reputation: 12837

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.

Upvotes: 1

Related Questions