By Alvin Alexander. Last updated: December 18, 2017
A cool feature of the Scala REPL is that you can reset/clear a REPL session. To do so, just issue the :reset
command, like this:
scala> :reset Resetting interpreter state. Forgetting this session history:
Assuming that you already have at least a little history in your REPL session, the :reset
command will show you everything that it dumps, so the full output looks more like this:
scala> :reset Resetting interpreter state. Forgetting this session history: trait Animal class Person(name: String) extends Animal class Employee(name: String) extends Person(name) def printPerson(b: Boolean)(implicit p: Person) = if (b) println(p) val p = new Person("person") val e = new Employee("employee") Forgetting all expression results and named terms: e, p, printPerson Forgetting defined types: Animal, Employee, Person
In my case I was testing implicit
values in parameter lists, and forgot to make the last two values implicit, so I decided to start my REPL session over again.
If you ever need to clear your Scala REPL session, it’s great that you can reset the session, rather than having to kill it and start over.