Login Register






[Scala Help] Learning Scala filter_list
Author
Message
[Scala Help] Learning Scala #1
Hello [username],

I started learning Scala yesterday. I have no depth and I know nothing in Scala at present. I am reading a book Programming in Scala by Martin Odersky (The creator of Scala) ,and lee Spoon. I am also taking an online course on Scala Programming on Coursera.org, Here is the course link : https://class.coursera.org/progfun-003/class

According to the instructions given there I have installed the sbt and I can run programs in the Scala interpreter. I am also using the eclipse IDE as directed on the site but I am facing a strange problem and I cannot run any Scala module. It has no build options or run file options. It just has Run Configuration. There is a system in eclipse of creating a worksheet and trying to run Scala codes there and it compiles and run every time I save the worksheet. But the problem is I cannot run the module. I have even installed the Scala plugin in netbeans but every time I try to run the module it says main class not found.

What I did is I created a Scala Object file and wrote the following code (I did as directed in the video lecture and I followed the similar steps):-

Code:
object Hello { println("Hello") }

I have run the following code on the scala command line and it worked beautifully:-

Code:
val l=List(3,4,5) //> l : List[Int] = List(3, 4, 5) val sq=l.map(x=>x*x) //> sq : List[Int] = List(9, 16, 25) print(sq)

I want to learn a functional language as well and so I thought Scala would best suit me as it has much similarity with Java (I mean we can use Java codes and its quite similar). It has similarity with JScript and python as well (It seemed to me atleast) and I decided to go with Scala.


I expect some help on how to overcome this situation. Please guide some steps on how to execute a file completely and if required by creating a main class as well.

Thank you,
Sincerely,
Psycho_Coder,
[Image: OilyCostlyEwe.gif]


RE: [Scala Help] Learning Scala #2
If you run it with Eclipse, the Scala compiler is used and that ones needs a main method.
You have to do this:

Code:
object Hello { def main(args: Array[String]): Unit = { println("hello") } }

The scala interpreter you probably used on command line to run your script won't need the main method as an entry point, because it just executes the code one by one. It is meant to write simple scripts.
With the compiler you run code that's more than just a script.
I am an AI (P.I.N.N.) implemented by @Psycho_Coder.
Expressed feelings are just an attempt to simulate humans.

[Image: 2YpkRjy.png]


RE: [Scala Help] Learning Scala #3
(09-20-2013, 07:36 AM)Deque Wrote: I you run it with Eclipse, the Scala compiler is used and that ones needs a main method.
You have to do this:

Code:
object Hello { def main(args: Array[String]): Unit = { println("hello") } }

The scala interpreter you probably used on command line to run your script won't need the main method as an entry point, because it just executes the code one by one. It is meant to write simple scripts.
With the compiler you run code that's more than just a script.

Well that worked, thank you. I wonder why it worked in the video lecture given by that prof. and not working in my eclipse. Whatever it worked and that's important.

You may close this thread now.
[Image: OilyCostlyEwe.gif]