

In summary, I hope this example of how to use the :paste command to let you enter multiline commands in the Scala REPL has been helpful. The best way to learn a new language is to create a simple file for that programming language and keep running it. However, you can’t always do this, and I usually prefer to type :paste and then enter my statements just like I would in an IDE.

For the example shown, you just need to add curly braces to the if statement to let the REPL know that a block is coming up:

It also displays the outcome and imports the result into the current scope.

Every line that we enter on the Scala prompt is interpreted and executed by Scala REPL. In some cases you can create multiline commands in the Scala REPL without using the :paste command. The Scala REPL is an interactive Scala shell, or you can think it as Scala interpreter. Entering multiline commands in the REPL without :paste In this example I paste in my complete multiline if statement, and then press :Īfter entering my four-line if statement, I pressed, and after that the line “// Exiting paste mode, now interpreting” was printed, followed by the output from my if statement (“that was true”). When you do this, the REPL prompts you to paste in your command - your multiline expression - and then press at the end of your command. Entering paste mode (ctrl-D to finish) This plugin adds a new button to run a REPL that works with Pants. Before entering your multiline statement, type the :paste command into the REPL: The Scala REPL in Intelllij for Pants project is known to be broken. If your statement doesn’t end on one line, boom! Resolving the problem with the :paste commandĪ simple way to get around this multiline statement problem is to use the :paste command in the REPL. scala> Console.printf( Today the outside temperature is a balmy.
#Scala repl code
The REPL generally just sees one line of code at a time, attempts to interpret it, and print the result of that line. This error happens because the Scala REPL environment isn’t exactly the same as working in something like an IDE. :2: error: ' ' expected but string literal found. You begin typing your if statement normally, but when you hit after your second line, you’ll see that everything blows up: When you want to test a multiline command/statement in the Scala REPL, you can easily run into a problem where the REPL gets confused, or more accurately, it attempts to evaluate your statement too early.Īs a simple example of this, imagine that you want to test the Scala if statement syntax. show more info on classes/objects in repl.Scala REPL in Ubuntu 20.04, you can read through the following sections of this article: How to Enter the Scala Command Line Interpreter Shell?įor entering the Scala command-line interpreter shell, you will have to launch the terminal of your Ubuntu 20. Using Scala REPL:įor using the Scala command-line interpreter shell, i.e. In this guide, we will explicate to you how you can use Scala REPL in Ubuntu 20.04. Finally, its result is computed by REPL and displayed on the shell. Whichever Scala expression you try to execute within this shell is first read by REPL, then it is converted into an executable template. REPL stands for Read-Evaluate-Print-Loop. You can create small Scala programs and execute them directly while staying within this shell using this shell. However, the Scala programming language also has a command-line interpreter shell known as REPL. You have learned to create Scala scripts and execute them through Ubuntu 20.04 terminal. By now, you would be well-aware of using the different functions of the Scala programming language.
