Skip to content

Instantly share code, notes, and snippets.

@InPermutation
Last active December 14, 2015 12:38
Show Gist options
  • Save InPermutation/5087331 to your computer and use it in GitHub Desktop.
Save InPermutation/5087331 to your computer and use it in GitHub Desktop.
throwup(fxn) -> creates the inductive case of exception-tail-call-optimization makecallable(fxn) -> creates the trampoline for exception-tail-call-optimization
function throwup(fxn) {
return function() {
throw [fxn, Array.prototype.slice.call(arguments)];
}
}
function makecallable(fxn) {
return function() {
var params = Array.prototype.slice.call(arguments);
while(params) {
try {
var r= fxn.apply(null, params);
return r;
}catch(e){
params = e[1];
fxn = e[0];
}
}
}
}
module.exports = {makecallable: makecallable, throwup: throwup};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment