Here is a possible solution:
(define (discriminant a b c k0)
(square b (lambda (v1)
(mult 4 a (lambda (v2)
(mult v2 c (lambda (v3)
(sub v1 v3 k0))))))))
(define (square a k1)
(mult a a k1))
(define (mult a b k2)
(k2 (* a b)))
(define (sub a b k3)
(k3 (- a b)))
(define (plus a b k4)
(k4 (+ a b)))
Please notice that this CPS variant of the program dictates a particular evaluation order:
- First we square b: b*b
- Multiply 4 and a
- Multiply the result of step 2 with c. Now we have 4*a*c
- Finally we subtract the result of step 3 from the result of step 1
After these steps - in this particular order - pass the final result b*b - 4*a*c to k0