How to echo user input in Scala REPL?

I teach an introductory programming class using Scala. We start with REPL. REPL has the error that when a student issues the readLine command, their input is not reflected. Is there any workaround I can offer or provide?

I don't have this problem when using Eclipse, but in a few weeks I will introduce Eclipse to my students.

+7
scala read-eval-print-loop
source share
2 answers

You can use power mode to access the REPL reader; it will give you a fully working readLine :

 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> repl.in.readLine("enter something: ") enter something: hello world res0: String = hello world scala> 

Edit : as pointed out by @ som-snytt, in 2.11 you can use reader instead of repl.in in the code above, which is shorter and easier to remember.

+4
source share

Use scala -Xnojline :

 scala> val l = readLine test l: String = test 

This, however, breaks some things, in particular the arrow keys, so you cannot modify previous commands.

If available, you can use rlwrap scala -Xnojline (should also be available on cygwin) to restore these functions.

Full credit for this post .

+2
source share

All Articles