Why introduce an entirely new language construct for such a specific use case?
Especially when what you want really behaves like a method.
I would propose to use a type-directed approach instead:
def myProgram: Application = { println(args.toList) }
Where we have:
@scala.annotation.implicitNotFound(
"This definition can only be used within an Application context")
case class ApplicationContext(args: Array[String])
type Application = given ApplicationContext => Unit
def args: Array[String] = given (c: ApplicationContext) => c.args
The compiler would generate an object with a main method for all top-level methods that have type Application
.
Then we should reap most of the benefits (including friendliness to new users), without any new language features. And this way, we can also easily call into such entry points from another entry point, or even from any place you want, really:
scala> myProgram given ApplicationContext(Array("hello"))
List(hello)