Using continuation passing style, many common language constructs can be written in a simple language with recursion, including loops (using trampolining), exceptions, generators and even function returns. I have found numerous examples of other language constructs, but all examples I have seen use if-statements directly. Noting the power of CPS, I got curious: Can one write an if-statement in CPS without using an if-statement directly?
The naive attempt would be something along these lines:
if_cps(condition, true_body, false_body, current_continuation)
{
if(condition) true_body(current_continuation);
else false_body(current_continuation);
}
but obviously this is a failure, since I used an if-statement directly.