How do chain commands in Scala interpreter?

254 views Asked by At

In windows batch, you chain commands with && operator. How do you do the same in scala interpreter? It looks stupid that I need :load file and call import mainobj._ after every load. Obviously, you want to chain them into one liner.

1

There are 1 answers

6
Callum On

You could write multiple statements in one line of Scala with ;

scala> val a:Int = 3; val b:Int = 4; println(a+b);
7
a: Int = 3
b: Int = 4

Or first type { then write your commands line by line finishing with }

scala> {
     | val x:Int = 1
     | val y:Int = 2
     | println(x + y)
     | }
3

Or you can use :paste to turn on paste mode, and then enter your code.

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

if (true)
  print("that was true")
else
  print("false")

// Exiting paste mode, now interpreting.

that was true