Skip to content

Instantly share code, notes, and snippets.

@jlongster
Last active April 30, 2016 18:36
Show Gist options
  • Save jlongster/93ed484120b00a68abf2bb72823ad858 to your computer and use it in GitHub Desktop.
Save jlongster/93ed484120b00a68abf2bb72823ad858 to your computer and use it in GitHub Desktop.
function bar(func) {
console.log('bar entered');
func(5);
console.log('bar exiting');
}
function foo() {
var x = callCC(function(cont) {
console.log('calling bar');
bar(cont);
console.log('done calling');
});
console.log('x:', x);
}
foo();
// Output:
//
// calling bar
// bar entered
// x: 5
function foo() {
var arr = callCC(function(cont) {
cont([cont, 0]);
});
var c = arr[0];
var v = arr[1];
if(v < 5) {
c([c, v + 1]);
}
else {
return v;
}
}
console.log(foo());
// Output:
//
// 5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment