I ran into 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 that code is the Continuation-Passing version of another piece of code:
(define (pyth x y)
(sqrt (+ (* x x) (* y y))))
However, I'm quite confused: How does that even work? How do you multiply a number by a lambda here? (* x x (lambda ...))
*&
,+&
andsqrt&
, i.e. a convention where an ampersand is appended to each function which accepts a continuation as the last parameter. It took me a while nevertheless to understand that these functions are not part of Scheme's standard operators, but implemented explicitly. – Ingathering