When I wrote a scala script, such as this simple logic:
$ cat MyTest.sc
println("testing!")
It can’t be complied by scalac due to no entry func exists:
$ scalac MyTest.sc
MyTest.sc:1: error: expected class or object definition
Is there a way that when I call scalac above, scalac translates the script automatically to the program below:
$ cat MyTest.scala
object MyTest { // auto enclosed in a object
def main(args:Array[String]):Unit = { // auto generating a main func
println("testing!")
}
}
After then I can run the compiling:
$ scalac MyTest.scala
for example, when calling this syntax:
$ scalac --a-new-option MyTest.sc
scalac will try to compile everything in the digital world, even if it’s a bash script.
Thank you.