Skip to content

Commit a191db0

Browse files
committed
rewrote in worksheet mode
1 parent 8a9be51 commit a191db0

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

tutorials/tour/_posts/2017-02-13-nested-functions.md

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,16 @@ previous-page: higher-order-functions
1414
In Scala it is possible to nest function definitions. The following object provides a `factorial` function for computing the factorial of a given number:
1515

1616
```tut
17-
object FactorialTest extends App {
18-
def factorial(x: Int): Int = {
17+
def factorial(x: Int): Int = {
1918
def fact(x: Int, accumulator: Int): Int = {
2019
if (x <= 1) accumulator
2120
else fact(x - 1, x * accumulator)
2221
}
2322
fact(x, 1)
24-
}
25-
println("Factorial of 2: " + factorial(2))
26-
println("Factorial of 3: " + factorial(3))
27-
}
23+
}
24+
25+
println("Factorial of 2: " + factorial(2))
26+
println("Factorial of 3: " + factorial(3))
2827
```
2928

3029
_Note: the nested function `fact` refers to variable `x` defined in the outer scope as a parameter value of `factorial`._

0 commit comments

Comments
 (0)