0

When a continuation is called as a procedure, does some jump occur?

For example, I have seen two use cases of continuation:

  1. Are the continuation created by call/cc and the continuation used for making a call to a function in CPS the same concept, and do both involve jump?

  2. When a continuation captured by a call/cc call is called, the program execution flow will jump to the call/cc call.

  3. When a function in CPS is called with a continuation, does similar jump also occur? (I am not sure)

    For example,

    (letrec ([f (lambda (x) (cons 'a x))]
             [g (lambda (x) (cons 'b (f x)))]
             [h (lambda (x) (g (cons 'c x)))])
      (cons 'd (h '())))   (d b a c)
     can be written in CPS as
    
    (letrec ([f (lambda (x k) (k (cons 'a x)))]
             [g (lambda (x k)
                  (f x (lambda (v) (k (cons 'b v)))))]
             [h (lambda (x k) (g (cons 'c x) k))])
      (h '() (lambda (v) (cons 'd v))))
    

    (lambda (v) (cons 'd v)) is a continuation passed to h, then to g and f, before it is eventually called. But when it is called, is there any jump also occurring?

  • 1
    Every call can be seen as a jump with closure structure so it doesn't jump more than usual. CPS can be seen as internal structure of a language so the continuation is how flow continues and the program never returns. The last continuation is `halt` – Sylwester Aug 06 '19 at 20:17
  • 1
    *not* the same. CPS *contingencies* are normal functions, tail-called -- there's no jumps, just normal tail call optimization (it's no more a jump than a normal function call is a jump, per "lambda is the ultimate goto"). `call/cc`-created continuations are more like `longjmp` from C. a source file's compilation can involve whole-program CPS transformation to *emulate* the true continuations. – Will Ness Aug 06 '19 at 22:28

0 Answers0