Skip to content

Instantly share code, notes, and snippets.

@folone
Created August 4, 2011 08:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save folone/1124712 to your computer and use it in GitHub Desktop.
Save folone/1124712 to your computer and use it in GitHub Desktop.
Scala continuations explanation. More on this there -> http://dcsobral.blogspot.com/2009/07/delimited-continuations-explained-in.html
reset {
// A
shift { cf: (Int=>Int) =>
// B
val eleven = cf(10)
// E
println(eleven)
val oneHundredOne = cf(100)
// H
println(oneHundredOne)
oneHundredOne
}
// C execution continues here with the 10 as the context
// F execution continues here with 100
+ 1
// D 10.+(1) has been executed - 11 is returned from cf which gets assigned to eleven
// G 100.+(1) has been executed and 101 is returned and assigned to oneHundredOne
}
// I
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment