2

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?

Jiri Kremser
  • 12,471
  • 7
  • 45
  • 72

2 Answers2

1

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.

Jiri Kremser
  • 12,471
  • 7
  • 45
  • 72
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
som-snytt
  • 39,429
  • 2
  • 47
  • 129
  • Unfortunately doesn't work for Scala 2.9.2 (`setExpandEvents()` method is missing on `JLineConsoleReader` class in that version) Also I had to replace `$r.r.in...` with `$r.repl.in...` to make it work. I accept this answer, because it solves the issue for newer versions of Scala, where the API is in place. – Jiri Kremser Jul 14 '13 at 16:22