Win a copy of Kotlin in Action this week in the Kotlin forum!
    Bookmark Topic Watch Topic
  • Mark post as helpful
  • send pies
  • Report post to moderator
Getting Started

  • Get it from
  • Scalazine - First Steps to Scala
  • The busy Java developer's guide to Scala - a series of articles on developerWorks by Ted Neward

  • Books

  • Programming in Scala < 3 free sample chapters!

  • Specs

  • Scala Specs in PDF

  • Get in the Loop

  • Join the scala-user mailing list
  • JavaRanch Scala Forum

  • An example

    To start with, here's a short Scala program that solves the first problem of Project Euler : If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23. Find the sum of all the multiples of 3 or 5 below 1000.

    More examples

    Scala is particularly well suited for problems that are defined recursively, or that can solved by recursive algorithms. Here are functions that calculate the factorial of a number (n!) and the numbers of the Fibonacci sequence.

    This recursive "fibonacci" code is considered a "natural" implementation as it mirrors the mathematical definition of the function very closely. However this recursive version is very inefficient, and will become slow very quickly for growing n. Consequently it is not unusual in functional languages to replace inefficient recursive functions with equivalent tail recursive versions. Here is a tail recursive version of "fibonacci":

    With this version the Scala compiler can detect the tail recursion and perform tail call optimization. The generated byte code will be no more inefficient than the code that is generated from the following imperative version.

    CategoryLearnSomethingNew ScalaFaq
      Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!