On this page:
1.11.1 Stack Space
1.11.2 CPS Transformation
1.11.3 Application

1.11 Continuations

Complete this assignment with Team Two.

1.11.1 Stack Space

Any program that consumes some amount of stack, when converted to CPS and run, suddenly consumes no stack space at all. Why?

1.11.2 CPS Transformation

CPS the following Racket function. You don’t need to CPS primitives such as empty?, first, rest, cons, cons? and <. You may also assume that the function argument to both of the functions is in CPS. Name the result filter/k as shown below.

; filter: (x -> bool) (listof x) -> (listof x)
(define (filter f l)
  (cond
    [(empty? l) empty]
    [else (cond
            [(f (first l)) (cons (first l)
                                 (filter f (rest l)))]
            [else (filter f (rest l))])]))
 
; filter/k: (x receiver -> doesn't) (listof x) receiver -> doesn't
(define (filter/k f l k)
  ....)

Now change the following expressions to use filter/k.
(define (less-than-three x)
   (< x 3))
(filter less-than-three
        (cons 1 (cons 4 empty))) ; this evaluates to (list 1)

1.11.3 Application

In 850 words or less, describe if and how your knowledge of continuations and CPS will help you in your future programming practice. Good answers might discuss how this concept can be applied in interesting programming environments or how knowledge of its subtleties clarifies or improves existing practices, techniques, tools, etc.