I am really sorry, this seems basic. I am using Programming in Scala and I have got to step 4:
Put this into a file named hello.scala:
@main def m():
println("Hello world from a script!"
At first I got an illegal start of definition error, since pivoting to using vs code I get the following:
(base) *dir* scala % scala hello.scala
Compiling project (Scala 3.5.1, JVM (21))
[error] ./hello.scala:2:12
[error] end of toplevel definition expected but '(' found
[error] println("hello world from script")
[error] ^
[error] ./hello.scala:1:11
[error] Declaration of method m not allowed here: only classes can have declared but undefined members
[error] @main def m():
[error] ^
Error compiling project (Scala 3.5.1, JVM (21))
I thought it might be a new line issue, so I moved everything onto one line like @main def m(): println("hello world from script") and I get the following:
(base) *dir* scala % scala hello.scala
Compiling project (Scala 3.5.1, JVM (21))
[error] ./hello.scala:1:23
[error] end of toplevel definition expected but '(' found
[error] @main def m(): println("hello world from script")
[error] ^
[error] ./hello.scala:1:11
[error] Declaration of method m not allowed here: only classes can have declared but undefined members
[error] @main def m(): println("hello world from script")
[error] ^
Error compiling project (Scala 3.5.1, JVM (21))
Using scalac hello.scala does not work either.
=methods don't start with:, rather:is used to specify the return type.:with=?