lunduniversity / introprog

Teaching material for "Introduction to Programming using Scala" at Lund University, LTH. http://cs.lth.se/pgk/
142 stars 171 forks source link

Example code gives compilation errors #652

Closed Biologisten closed 2 years ago

Biologisten commented 2 years ago

2.1.17 page 68

object HelloScalaArgs:
  def main(args: Array[String]): Unit = // en primitiv main-metod utan @main
  var i = 0
    while i < args.size do:
      println(args(i))
      i = i + 1

Gives error on line 4 "do:"

2.1.19 page 69

// spara nedan i filen 'myscript.scala'
println("Hej alla mina argument:")
for arg <- args do println("Hej: " + arg)

run with scala myscript.scala Compilation error "Illegal start of toplevel definition". Script does not run

bjornregnell commented 2 years ago

Thanks! Good catch. There is a colon too much. Does it work if you remove the colon?

And yes, the script thing does not seem to work without a main anymore. I'll change it to include a main.