Inline function: handle recursive calls

This commit is contained in:
Mikhail Glukhikh
2017-03-28 18:27:29 +03:00
parent e79f006659
commit 75bb599991
7 changed files with 54 additions and 4 deletions
@@ -0,0 +1 @@
fun fact(x: Int): Int = if (x < 2) 1 else x * <caret>fact(x - 1)
@@ -0,0 +1,4 @@
fun fact(x: Int): Int = if (x < 2) 1 else {
val x1 = x - 1
x * if (x1 < 2) 1 else x1 * fact(x1 - 1)
}
@@ -0,0 +1,3 @@
fun fact(x: Int): Int {
return if (x < 2) 1 else <caret>fact(x - 1)
}
@@ -0,0 +1,6 @@
fun fact(x: Int): Int {
return if (x < 2) 1 else {
val x1 = x - 1
if (x1 < 2) 1 else fact(x1 - 1)
}
}