Last active
December 14, 2015 13:48
-
-
Save InPermutation/5095756 to your computer and use it in GitHub Desktop.
Show how to optimize corecursive functions using …exceptions?!
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
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