Using continuation passing style, many common language constructs can be written in a simple language with recursion, such as 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.
How would I write an if-statement in continuation passing style without an if-statement?
continuations
OK, so following the advice given by @Andrej Bauer (in the comments to my question) and @Derek Elkins (in his answer), it seems that we can actually do if-statements in CPS!I will attempt to write out the suggested answer:The idea is to do booleans in pure Lambda calculus, e.g. using Church encoding. The CPS version would be like this:true(a, b, continuation){    a(continuation);}false(a, b, continuation){    b(continuation);}if_cps(condition, true_body, false_body, current_continuation){     condition(true_body, false_body, current_continuation);}To use if_cps, we would do like this:Make a closure that captures the variables needed and assign it to true_bodyMake a closure that captures the variables needed and assign it to false_bodyAssign one of the true or false functions to conditionCall if_cps with the parameters above as well as the continuation.The true_body and false_body closures need to be arity one functions, taking the continuation as a parameter.