UNPKG

lisp.js

Version:
33 lines (27 loc) 711 B
function plus(a, b) { return a + b; } function plus_cont(a, b, then) { return trampolineBounce(function() { return then(a+b); }); } function trampolineBounce(func) { return { type: "bounce", func: func }; } function runTrampoline(func) { var step = func(function(result) { return { type: "result", result: result }; }); while (step.type === "bounce") step = step.func(); return step.result; } var onePlusTwoPlusThree = runTrampoline(function(then) { return plus_cont(1, 2, function(onePlusTwo) { return plus_cont(onePlusTwo, 3, function(result) { return then(result); }); }); }); console.log(onePlusTwoPlusThree);