I am learning CPS with Racket and I managed to write these functions:
;lift a regular single-arg function into CPS
(define (lift/k f)
(lambda (x k)
(k (f x))))
;compose two CPS functions
(define (compose/k f g)
(lambda (x k)
(g x (lambda (y)
(f y k)))))
They seem to be working correctly.
(define (is-two/k x k)
(k (= x 2)))
(define is-not-two/k (compose/k (lift/k not) is-two/k))
(is-not-two/k 3 display)
(is-not-two/k 2 display)
I am wondering if these features remain โtrue CPSโ. Am I confused the "true" sequel with these features? Is it Kosher to use function composition methods in CPS? Is it encouraged? Or will this be considered a โcompromiseโ for this? Is there another CPS-y way to do this?
Yes, I know that I just asked 5 questions, but the basic idea of โโall of them (that I'm not sure that I understand correctly) is the same. Explanations in other Lisps, Haskell, Erlang, or other functional languages โโare beautiful.
source
share