Question

In a Wikipedia article about CPS there is the following code snippet, ostensibly from Scheme:

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

I cannot find any other examples, or an explanation for the usages of "pyth&", "*&", and "+&". Much Googling has turned up only that there are other forms such as "=&" and "/&".

Was it helpful?

Solution

Those are just function names, pyth& is the CPS pythagoras procedure, *& is a CPS multiplication procedure and +& is a CPS addition procedure, different from their usual counterparts because they receive a continuation in the last parameter, the & at the end is simply a naming convention to remind you of this, which is stated at the beginning of the linked paragraph:

In CPS, each procedure takes an extra argument representing what should be done with the result the function is calculating

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top