[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: call/cc




Just to step away from the token-counting aspect of this, here's a
more concrete example.  Suppose we were manipulating lines and we need
to find the equation of the line.  A CPS function that computed this
might be called like this:

(line-equation line
  (lambda (slope y-intercept)
    (format t "~&The line is ~d X + ~d" slope y-intercept))
  (lambda (x-intercept)
    (format t "~&The line is vertical through X = ~d" x-intercept)))

This actually isn't too bad.  Some people find the LAMBDA and the
anonymous procedures scary (and noisy).

What would this look like in other languages?  Bear in mind that the
`return value' of line-equation will be parameterized on the union of
the return types of the continuations, and that the lambda expressions
ought to be able to refer to lexical variables (although they are
not needed here).

(Thanks to Arthur Gleckler for inspiration for this example.)