Jump to content

Introduction to Delimited Continuations/The rest of the program

From Wikiversity

When the program reads a line from the console, something interesting has happened. The flow of the program has been interrupted, and it cannot proceed until the user has typed a line of text. The rest of the program is now a function which takes a String and prints a message to the console, and is invoked only when the user has provided input.

The "rest of the program" is a continuation, and looks like this:

val k = { name: String => println("Hello, " + name + "!") }

The run method can be rearranged to invoke the continuation once the user has typed a line of text.

def run() = {
  println("What is your name?")
  k(readln())
}