I am trapped at work with a locked down pc. But I am trying to practice my Scala. I am using Ideone.com since I can't even install scalac
...
Anyway this is not compiling:
class DPt(var name: String, var x: Double, var y: Double){
def print = println("DPt; name: " + name + " x: " + x + " y: " + y)
}
object Main {
def main(args: Array[String]) {
val pt0 = new DPt("Joe", 1.0, 1.0)
println("checking generated accessor: " + pt0.x)
pt0 print
pt0.x_=(3.0)
pt0 print
}
}
I get this message back from the Ideone.com scala compiler:
Main.scala:12: error: Unit does not take parameters
pt0 print
^
one error found
spoj: The program compiled successfully, but Main.class was not found.
Class Main should contain method: def main(args: Array[String]).
However, when I add semicolons to the end of the statements, like this:
class DPt(var name: String, var x: Double, var y: Double){
def print = println("DPt; name: " + name + " x: " + x + " y: " + y)
}
object Main {
def main(args: Array[String]) {
val pt0 = new DPt("Joe", 1.0, 1.0);
println("checking generated accessor: " + pt0.x);
pt0 print;
pt0.x_=(3.0);
pt0 print;
}
}
I find the infix and postfix notation in Scala to be AWESOME, But I must be missing something. Why doesn't Scala consider the end of the line to be the end of the statement?
Second poster on this blog seems to have the answer. The Scala people should get on this. Such an annoyance.... Although this is about the first annoying this I've encountered in this otherwise beautiful language. http://www.scala-lang.org/node/4143
Another explanation straight from the documentation: http://docs.scala-lang.org/style/method-invocation.html