Running a program from the Windows 10 command line fails

This tutorial explains how to run following scala program (script) from a command line in Windows 10. But when I run the following command, it gives me the error: expression expected but '.' found

scala> scala args.scala Hello World!

Remarks:

  1. The full path of the file is C:\Test\args.scala. But even if I type the full path in the above command line, it still gives the exact same error.

  2. The inline commands such as the following work fine:
    scala> println (“Hello World”)
    scala> 7 * math.Pi

Question: What I may be missing and how we can fix the issue?

Instructions from the above linked tutorial:

Open your editor, and write the following small program:

println(“Your arguments are:”)

for (i ← 0 until args.length) {
println(i + ": " + args(i))
}

Save it as a file named args.scala.

Try running this program from the command line, with arguments, such as:

scala args.scala Hello World!

Don’t follow random Scala tutorials on the web, they are quite bad. Often they are very outdated, they are written for Scala 2.9, 2.10, 2.11 etc.

Learn from official sources.
Online courses:
https://docs.scala-lang.org/online-courses.html
Books:
https://docs.scala-lang.org/books.html

The scala code runner was not very good and soon it is being replaced with scala-cli which will become the official code runner. https://scala-cli.virtuslab.org/

So I recommend using scala-cli. If you need more detailed support, drop by Discord for live chat, you can get much faster / better feedback there. Scala

2 Likes

That website was by a professor teaching intro to CS over a decade ago.

Unfortunately, there is not yet much documentation for Scala that is really usable for beginners in programming.

Teachers provide the usual Scala resources.

The “mastermind” example still runs.

I would take exception, so to speak.

Context is everything.

1 Like