It seems pretty easy. But you have to use println to print something.
➜ ~ cat hello.scala
println("hello, world")
➜ ~ scala hello.scala
hello, world
➜ ~ scala -Vprint:parser hello.scala
[[syntax trees at end of parser]] // hello.scala
package <empty> {
object Main extends scala.AnyRef {
def <init>() = {
super.<init>();
()
};
def main(args: Array[String]): scala.Unit = {
final class $anon extends scala.AnyRef {
def <init>() = {
super.<init>();
()
};
println("hello, world")
};
new $anon()
}
}
}
hello, world
➜ ~
or there are a few ways to feed lines to the REPL, which prints results for you.
➜ ~ cat calc.scala
2 + 2
➜ ~ scala < calc.scala
Welcome to Scala 2.13.1 (OpenJDK 64-Bit Server VM, Java 11.0.3).
Type in expressions for evaluation. Or try :help.
scala> 2 + 2
res0: Int = 4
scala> :quit
➜ ~
See also -i
, -I
, -e
, and the :load
and :paste
commands.
As shown in the other answer, it will also look for a Java-style main method in an object. That's how you'd normally compile a program entry point.