Suppose I have the following functions:
function f(x) { return x + 1; }
function g(x) { return x * 2; }
function h() { return 5; }
How could I convert the expression f(g(h()))
into continuation passing style? I know that h
is transformed to:
function h(ret) { ret(5); }
However, I don't know how to convert the expression f(g(h()))
into CPS.
In addition, what if f
takes 2 arguments instead of 1? How would that look in CPS?
Furthermore, what if f
and g
don't take any arguments at all? How does that look in CPS?