Skip to content

Instantly share code, notes, and snippets.

@InPermutation
Last active December 14, 2015 13:48
Show Gist options
  • Save InPermutation/5095756 to your computer and use it in GitHub Desktop.
Save InPermutation/5095756 to your computer and use it in GitHub Desktop.
Show how to optimize corecursive functions using …exceptions?!
var throwup = require('throw').throwup, makecallable = require('throw').makecallable;
var even = throwup(_even),
odd = throwup(_odd);
var r = makecallable(_even)(parseInt(process.argv[2], 10) || 5000, 0);
console.log('found2', r);
function _even(n,j) {
if(n>0) return odd(n-1, j+1);
else return ['even', j];
}
function _odd(n, j) {
if(n>0) return even(n-1, j+1);
else return ['odd', j];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment