Scala, first example.
Posted on February 8, 2007
Here is an example of code in Scala. Scala is a functional/OO hybrid language for JVM and .NET virtual machines.
I started playing with it today.
object RSSDump extends Application {
val url = "http://www.digg.com/rss/index.xml"
val elem = scala.xml.XML.load(url)
val items = elem \\ "item"
for(val item <- items) {
val title = (item \ "title").text
Console.println(title)
}
}
Some things to note:
object RSSDump is a singleton object, it has a state.
val is a constant value, it can not change. we can do
var i: int i = i + 1 // increment variable
if we have to.
Scala functions can have any names, such as \ \\ ! !?, so we and not limited to overloading +-=.
Scala has XML processing build in, elem \\ “item”. More about it in the next post.
Filed Under Uncategorized |
Leave a Comment
If you would like to make a comment, please fill out the form below.