2 Replies - 22156 Views - Last Post: 27 July 2015 - 01:51 AM

#1 macosxnerd101  Icon User is offline

  • Games, Graphs, and Auctions
  • member icon




Reputation: 11315
  • View blog
  • Posts: 42,636
  • Joined: 27-December 08

Week 31- Scala

Post icon  Posted 21 September 2010 - 09:39 PM

Posted Image

This week's challenge is Scala, a statically typed hybrid functional-Object Oriented language. In Scala, every value is expressed as an Object. It also has features for inheritance, and a composition-based replacement for multiple inheritance. Scala also provides functional programming features including functions as values, anonymous functions, higher-order functions, nested functions, and currying. It also supports the algebraic pattern matching familiar to many other functional languages.

Scala is a compiled language, designed to run on the JVM. As such, it is compiled to Java Bytecode, and can interact with all standard Java libraries.

Resources:
The Scala Website
DIC Functional Programming Forum

Is This A Good Question/Topic? 0
  • +

Replies To: Week 31- Scala

#2 Dogstopper  Icon User is offline

  • The Ninjaducky
  • member icon

Reputation: 2930
  • View blog
  • Posts: 11,205
  • Joined: 15-July 08

Re: Week 31- Scala

Posted 02 November 2010 - 08:29 PM

For now, I wrote the famed Hello World Application!

object HelloWorld {
	def main(args: Array[String]) {
		println("Hello World");
	}
}



I sort of like the idea of a compiled object. In this case, HelloWorld is a Singleton object/class mix instead of a class. Supposedly, this idea gets rid of static variables in Java entirely. I'm not crazy about the syntax for method definitions, but I'll get over it.
Was This Post Helpful? 0
  • +
  • -

#3 g4143  Icon User is offline

  • New D.I.C Head

Reputation: 7
  • View blog
  • Posts: 31
  • Joined: 30-April 09

Re: Week 31- Scala

Posted 27 July 2015 - 01:51 AM

Scala is a language that should give the legions of Java programmers coding joy-gasms but for one reason or another they mostly have rejected the language(Scala). Here's a short example of the possibles with Scala.

The code reads the command line args and tries to open and read valid files.

import scala.io.Source

object testit {

  def main(args: Array[String]): Unit = {
    
    args.foreach(
      (filename:String)=>{
        getFileContents(filename) match {
          case (sc, Some(s)) => s.foreach(println)
          case (f, None) => println(s"Open/Read failed with: $f")
        }
      }
    )
  }
  
  def getFileContents(filename:String):(String, Option[Iterator[String]]) = {
    
    (util.Try(Source.fromFile(filename).getLines()) 
      match {
        case util.Success(s) => ("Success", Some(s))
        case util.Failure(f) =>  (f.getMessage(), None)
    })
    
  }
  
}



Was This Post Helpful? 0
  • +
  • -

Page 1 of 1