Back to slide -- Keyboard shortcut: 'u'        next -- Keyboard shortcut: 'n'          cps1.scm - A function programmed in both direct style and continuation passing style.Lecture 3 - slide 33 : 43
Program 1

(define (p-direct a b)
  (* (+ a b) (- a b)))

(define (p-cps a b k0)
  (plus a b (lambda(v1)
              ; given the sum of and b in v1, now compute a-b and
              ; the product. 
              (sub a b (lambda(v2)
                         ; given the sum in v1 and the difference in v2, now 
                         ; carry out the rest of the computation (the multiplication)
                         ; and pass the result to k0.
                         (mult v1 v2 k0))))))

; Variants of +, -, and * with continuation parameters.
(define (plus a b k) (k (+ a b )))
(define (sub a b k)  (k (- a b)))
(define (mult a b k) (k (* a b)))