Last active
December 14, 2015 12:38
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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