diff options
Diffstat (limited to 'scala.html.markdown')
-rw-r--r-- | scala.html.markdown | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/scala.html.markdown b/scala.html.markdown index c7a8842e..bb20f624 100644 --- a/scala.html.markdown +++ b/scala.html.markdown @@ -252,7 +252,7 @@ weirdSum(2, 4) // => 16 // The return keyword exists in Scala, but it only returns from the inner-most // def that surrounds it. // WARNING: Using return in Scala is error-prone and should be avoided. -// It has no effect on anonymous functions. For example: +// It has no effect on anonymous functions. For example here you may expect foo(7) should return 17 but it returns 7: def foo(x: Int): Int = { val anonFunc: Int => Int = { z => if (z > 5) @@ -260,9 +260,10 @@ def foo(x: Int): Int = { else z + 2 // This line is the return value of anonFunc } - anonFunc(x) // This line is the return value of foo + anonFunc(x) + 10 // This line is the return value of foo } +foo(7) // => 7 ///////////////////////////////////////////////// // 3. Flow Control @@ -301,7 +302,7 @@ do { // Recursion is the idiomatic way of repeating an action in Scala (as in most // other functional languages). // Recursive functions need an explicit return type, the compiler can't infer it. -// Here it's Unit, which is analagous to a `void` return type in Java +// Here it's Unit, which is analogous to a `void` return type in Java def showNumbersInRange(a: Int, b: Int): Unit = { print(a) if (a < b) @@ -480,7 +481,7 @@ class SaintBernard extends Dog { def bite = false } -scala> b +scala> val b = new SaintBernard res0: SaintBernard = SaintBernard@3e57cd70 scala> b.breed res1: String = Saint Bernard @@ -598,7 +599,7 @@ List("Dom", "Bob", "Natalia") foreach println s.map(sq) -val sSquared = s. map(sq) +val sSquared = s.map(sq) sSquared.filter(_ < 10) @@ -716,7 +717,7 @@ import scala.collection.immutable.{Map => _, Set => _, _} // Java classes can also be imported. Scala syntax can be used import java.swing.{JFrame, JWindow} -// Your programs entry point is defined in a scala file using an object, with a +// Your program's entry point is defined in a scala file using an object, with a // single method, main: object Application { def main(args: Array[String]): Unit = { |