value of that block of code, and if the block of code is the body of a function, it will be returned by the function. To make it clear that all functions are expressions, even methods that return Unit are written with an equals sign def printValue(x: String): Unit = { println("I ate a %s".format(x)) } or equivalently (with type inference, and omitting the unnecessary braces): def printValue(x: String) = println("I ate a %s" format x) Type inference Due to type inference, the type of variables, function return values, and many other expressions can typically be omitted, as the compiler can deduce it. Examples are val x = "foo" (for an immutable constant or immutable object) or var x = 1.5 (for a variable whose value can later be changed). Type inference in Scala is essentially local, in contrast to the more global Hindley-Milner algorithm used in Haskell, ML and other more purely functional languages. This is done to facilitate object-oriented programming. The result is that certain types still need to be declared (most notably, function parameters, and the return types of recursive functions), e.g. def formatApples(x: Int) = "I ate %d apples".format(x) or (with a return type declared for a recursive function) def factorial(x: Int): Int = if (x == 0) 1 else x*factorial(x - 1) Anonymous functions In Scala, functions are objects, and a convenient syntax exists for specifying anonymous functions. An example is the expression x => x < 2, which specifies a function with one parameter, that compares its argument to see if it is less than 2. It is equivalent to the Lisp form (lambda (x) (< x 2)). Note that neither the type of x nor the return type need be explicitly specified, and can generally be inferred by type inference; but they can be explicitly specified, e.g. as (x: Int) => x < 2 or even (x: Int) => (x < 2): Boolean. Anonymous functions behave as true closures in that they automatically capture any variables that are lexically available in the environment of the enclosing function. Those variables will be available even after the enclosing function returns, and unlike in the case of Java's anonymous inner classes do not need to be declared as final. (It is even possible to modify such variables if they are mutable, and the modified value will be available the next time the anonymous function is called.)