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. Commented 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.

Sign up to request clarification or add additional context in comments.

1 Comment

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.
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.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.