Skip to content

Instantly share code, notes, and snippets.

@paniq
Last active October 3, 2016 04:45
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 paniq/c4e4e8198a5edaa9a9dcfac044fa1e7d to your computer and use it in GitHub Desktop.
Save paniq/c4e4e8198a5edaa9a9dcfac044fa1e7d to your computer and use it in GitHub Desktop.
// so this is a typical implicit-continuation function
// as we know it from many languages:
function myfunc (f) {
f(2);
return 3;
}
// but this is how that function looks internally,
// with explicit control flow, invisible variables
// put in diamond brackets:
function myfunc (f, <return>) {
// we pass a continuation (effectively a callback) to f...
f(2,
function (x) {
// ...in which we call <return> to get out of it
<return>(3);
// if we had never called <return>, the program
// would have ended here, because the interpreter
// does not maintain a function stack.
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment