Continuation style in the circuit?

I came across this code on Wikipedia :

(define (pyth x y k)
    (* x x (lambda (x2)
        (* y y (lambda (y2)
            (+ x2 y2 (lambda (x2py2)
                (sqrt x2py2 k))))))))

The article says that this code is a version of continuing the transfer of another piece of code:

(define (pyth x y)
    (sqrt (+ (* x x) (* y y))))

However, I am very confused: how does it work? How do you multiply a number by lambda here?(* x x (lambda ...))

+5
source share
1 answer

The Wikipedia example *does not mean the same as the *regular example.

I would rewrite the Wikipedia example:

(define (pyth x y k)
    (cps-* x x (lambda (x2)
        (cps-* y y (lambda (y2)
            (cps-+ x2 y2 (lambda (x2py2)
                (cps-sqrt x2py2 k))))))))

In this form, each of the functions cps-xxxperforms the specified operation, and then passes the result to the last argument. You can call it like this:

(pyth 2 3 display)

2 3, 6, 6 display. ( cps-display, (), , ).

+5

All Articles