Created
February 5, 2013 21:20
-
-
Save Sgeo/4717756 to your computer and use it in GitHub Desktop.
Demonstration of mutually recursive tail-call optimized functions in Scala.
This file contains 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
/* code taken verbatim from http://www.scala-lang.org/api/current/index.html#scala.util.control.TailCalls$ */ | |
def isEven(xs: List[Int]): TailRec[Boolean] = | |
if (xs.isEmpty) done(true) else tailcall(isOdd(xs.tail)) | |
def isOdd(xs: List[Int]): TailRec[Boolean] = | |
if (xs.isEmpty) done(false) else tailcall(isEven(xs.tail)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
http://ideone.com/QC6S1n