Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make my scala program quit and return to the REPL?

So I made this scala file and it works great when I load it into the REPL. What I want to do though is when the user inputs "Q", it exits the program and returns to the REPL. I already have readLine set up with a case match that says:

case "Q" =>

I just don't know what to put after it to make the program quit.

Thanks

like image 689
Chris Avatar asked Dec 09 '22 16:12

Chris


1 Answers

You can use System.exit(0) provided you fork a new console / REPL. If you run via SBT, then fork in console := true will accomplish that. If you're launching a REPL from within your code and using run in instead of console, then you'd want fork in run.

If you want to run a stand-alone REPL, then start your program and eventually have it exit back to the REPL, then you'll need to simply stop your read loop and return out of the entry-point method you called to start it up.

Given how little code you included, it's hard to say much more than this.

like image 103
Randall Schulz Avatar answered Jan 04 '23 19:01

Randall Schulz