8

I'm teaching an introductory programming class, using Scala. We are starting with the REPL. The REPL has a bug in that, when the student enters a readLine command, their input is not echoed. Is there some workaround that I can suggest or provide?

I don't have this trouble when using Eclipse, but it will be some weeks before I introduce Eclipse to my students.

1
  • @som-snytt reader.readLine doesn't work with 2.10 for some weird reason. I am guessing that's the problem. Aug 31, 2013 at 21:43

2 Answers 2

4

You can use power mode to get access to the REPL's 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 @som-snytt pointed out, in 2.11 you can use reader instead of repl.in in the above code, which is both shorter and easier to remember.

1
  • Thanks! repl.in.readLine works perfectly; reader.readLine does not. <br> On my Mac, I get error: not found: value reader<br> On Windows, I get error: value reader in class Global cannot be accessed in scala.tools.nsc.Global <br> repl.in.readLine is probably better for my students in any case, as it emphasizes that this is only for the REPL. Sep 1, 2013 at 23:10
2

Use scala -Xnojline :

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

This does however break some things, in particular arrow keys, so you can't modify previous commands.

If available, you can use rlwrap scala -Xnojline (should be available on cygwin too) to restore those functionalities.

Full credit to this post.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.