Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Code breaks when using Continuation-passing style #3

Open
RicoP opened this Issue · 0 comments

1 participant

@RicoP

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
Something went wrong with that request. Please try again.