User Tools

Site Tools


λ Continuation passing style - direct

======= Algorithm ======= <syntax js> // non-continuation-passing-style // returns the square of x function sqr(x) { return x * x; } // this function exists purely to highlight the callbacks function log(value) { console.log(value); } // non CPS use, sqr simply returns 7*7 // which we pass to the log function // this is the same as log(sqr(7)) var r = sqr(7); log(r); </syntax> ======= Support ======= <syntax js> // Stubbed console. if (typeof console === "undefined") { console = { log: function() {} }; } </syntax> ======= Tests ======= <syntax js> </syntax> ======= Options ======= <syntax js> { "title":"Continuation passing style - direct", "height":"280px" }</syntax> ======= Visualisation ======= <syntax html> <html> <head> <style> pre {display:block} </style> <script> function globals(forCloning) { if (forCloning) { return {}; } else { return { console: { log:function($ret, $prev, str) { if (typeof str === "undefined") { $ret(undefined, $prev); } else { var msg = document.createElement("pre"); msg.innerHTML = "> " + str; document.body.appendChild(msg); var newPrev = function() { document.body.removeChild(msg); $prev(); } $ret(undefined, newPrev); } } } }; } } function update(n, x) { } </script> </head> <body> </body> </html> </syntax>

algorithm/continuation_passing_style-direct.txt · Last modified: 2015/02/02 08:28 (external edit)