Code breaks when using Continuation-passing style #3

Open
RicoP opened this Issue Dec 10, 2012 · 0 comments

Comments

Projects
None yet
1 participant

RicoP commented Dec 10, 2012

The following code breaks.

function factorial_cps(n, k) {
  if (n === 0) return k(1);
  return factorial_cps(
    n - 1, 
    function(result) { 
      return k(n * result); 
    });
}


function identity(x) { return x; }

var f = factorial_cps(5, identity); // 120

console.log(f); 

The problem is the

    __k = function (result) {
                    {
                        __tcor = k(n * result);
                        break tco;
                    }}

Which simply doesn't work. I guess there is no trivial solution for that but it would be very cool to be able to transform CPS code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment