Scala paste mode

 520 total views,  2 views today

Welcome to Scala series. In this tutorial, you will learn about Scala paste mode.

When you want to run multiple lines of code in a single go,I would suggest you to use :paste mode and avoid REPL. The reason is, REPL causes evaluation of the variable to early and might be bit odd to debug each and every line of code.

In Scala command line utility, each line of code will be treated as a single program.

scala> val i = 10;
i: Int = 10

scala> val i = "hi";
i: String = hi

If you notice the above lines of code, it is overwriting the value of i.

But in :paste mode,it wont allow us to overwrite the value.

Instead of giving each line in command line and executing ,we can execute a complete block of code. Use :paste

and to run the block , ctrl+d to execute it.

scala> :paste
// Entering paste mode (ctrl-D to finish)

val i =10;
val i = "raj"

// Exiting paste mode, now interpreting.

<console>:24: error: i is already defined as value i
       val i = "raj"

In Paste mode, you can run your entire code and unit test in Command line itself.

Scala paste mode execution is like working in the IDE like Eclipse and IntelliJ.

References : Scala Documentation

If you want to lean more about REPL.

Thanks for reading. Please leave your comments and give us a thumbs up!

Tags :

About the Author


Hey There, My name is Rajasekar and I am the author of this site. I hope you are liking my tutorials and references. Programming and learning new technologies are my passion. The ultimate idea of this site is to share my knowledge(I am still a learner :)) and help you out!. Please spread your words about us ( and give a thumbs up :) Feel free to contact me for any queries!.