I have a file called sumit.scala with the following contents
object sumit {
def main(args: Array[String]) = {
val start:Double = System.nanoTime
total_select_values(1 to 15000, {e => true})
val end:Double = System.nanoTime
println("time " + (end - start)/ 1000000000.0)
println("")
}
}
def total_select_values(list: Range, selector : Int => Boolean) = {
var sum = 0
list.foreach { e =>
if (selector(e)) sum += e
}
sum
}
i'm trying to compile it on the command line
scalac sumit.scala
which compiles without error but when i run it
scala sumit
i get a bunch of errors, i'm new to scala and i'm just trying to time this code once it's compiled to see the performance difference. I've tried putting my "total_select_values" in the object and out (as shown here) with no difference.
Thanks for any help!
Updated with Scala info and the actual error
Scala version 2.11.4 Java 1.7.0_40
java.lang.NoSuchMethodException: sumit.main([Ljava.lang.String;) at java.lang.Class.getMethod(Unknown Source) at scala.reflect.internal.util.ScalaClassLoader$class.run(ScalaClassLoader.scala:66) at scala.reflect.internal.util.ScalaClassLoader$URLClassLoader.run(ScalaClassLoader.scala:101) at scala.tools.nsc.CommonRunner$class.run(ObjectRunner.scala:22) at scala.tools.nsc.ObjectRunner$.run(ObjectRunner.scala:39) at scala.tools.nsc.CommonRunner$class.runAndCatch(ObjectRunner.scala:29) at scala.tools.nsc.ObjectRunner$.runAndCatch(ObjectRunner.scala:39) at scala.tools.nsc.MainGenericRunner.runTarget$1(MainGenericRunner.scala:65) at scala.tools.nsc.MainGenericRunner.run$1(MainGenericRunner.scala:87) at scala.tools.nsc.MainGenericRunner.process(MainGenericRunner.scala:98) at scala.tools.nsc.MainGenericRunner$.main(MainGenericRunner.scala:103) at scala.tools.nsc.MainGenericRunner.main(MainGenericRunner.scala)
The function
Has to go inside an object or class. This appears to be a constraint of Scala based on the JVM; can't have true free functions.