Just another update

This commit is contained in:
Ingy döt Net 2015-02-20 00:35:01 -05:00
parent a25938f123
commit 00a190b0a6
6591 changed files with 94363 additions and 23227 deletions

View file

@ -1,2 +1,5 @@
{{Control Structures}}
In this task, we document common flow-control structures. One common example of a flow-control structure is the <tt>goto</tt> construct. Note that [[Conditional Structures]] and [[Iteration|Loop Structures]] have their own articles/categories.
In this task, we document common flow-control structures.
One common example of a flow-control structure is the <tt>goto</tt> construct.
Note that [[Conditional Structures]] and [[Iteration|Loop Structures]]
have their own articles/categories.

View file

@ -0,0 +1,26 @@
import Goto._
import scala.util.continuations._
object Goto {
case class Label(k: Label => Unit)
private case class GotoThunk(label: Label) extends Throwable
def label: Label @suspendable =
shift((k: Label => Unit) => executeFrom(Label(k)))
def goto(l: Label): Nothing =
throw new GotoThunk(l)
private def executeFrom(label: Label): Unit = {
val nextLabel = try {
label.k(label)
None
} catch {
case g: GotoThunk => Some(g.label)
}
if (nextLabel.isDefined) executeFrom(nextLabel.get)
}
}