Created
November 18, 2016 17:48
-
-
Save kevinmeredith/c27cef5e7c0a33137091950a6a3eb578 to your computer and use it in GitHub Desktop.
Mutual Recursion odd/even
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| scala> :paste | |
| // Entering paste mode (ctrl-D to finish) | |
| import scala.annotation.tailrec | |
| @tailrec | |
| def odd1(n: Int): Boolean = { | |
| if (n == 0) false | |
| else even1(n - 1) | |
| } | |
| @tailrec | |
| def even1(n: Int): Boolean = { | |
| if (n == 0) true | |
| else odd1(n - 1) | |
| } | |
| // Exiting paste mode, now interpreting. | |
| <console>:14: error: @tailrec annotated method contains no recursive calls | |
| def odd1(n: Int): Boolean = { | |
| ^ | |
| <console>:20: error: @tailrec annotated method contains no recursive calls | |
| def even1(n: Int): Boolean = { | |
| ^ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment