Maybe I’m missing something, but I find experimenting with code in the REPL better excersise for my fingers than for my brain.
Let’s say you’ve defined a simple class (excuse the crappy example):
scala> class Farmer(){var name = ""
| def apply (name: String) = {this. name = name}
| override def toString():String={name}
| }
defined class Farmer
scala>
Is there a way to get that whole definition and make a change to it, without retyping or ‘up-arrowing’ line by line. For example, say I just wanted to add one function definition:
scala> class Farmer(){var name = ""
| def apply (name: String) = {this.name = name}
| override def toString():String={name}
| def +(surname: String) = {name = name + " " + surname}
| }
defined class Farmer
scala>
In other words, is there a way to tell REPL to replay the full multi-line entry from the previous input (up to a certain line), rather than just one line at a time (as happens when pressing the up arrow)?
In ‘Happy land’ it would have been nice to do something like, pressing ALT and then typing toString and then hitting return, and then the REPL will retype:
scala> class Farmer(){var name = ""
| def apply (name: String) = {this.name = name}
| override def toString
So basically the REPL retypes your code for you, up to the point you specified.
If anyone have any ideas on how to make using the REPL a bit more efficient than what I’m doing, I’d love to hear from them.
How about copy&paste? Scala will detect that you are pasting from a repl session, and act accordingly (that is, ignore “scala>” and “|”). Though it’s more readable if you use :paste mode to do stuff.
Otherwise, you might be happier with another repl. I find that ScalaConsole is pretty good for this kind of stuff.