Scheme Continuation: What's the difference between call 'call/cc' in top level and non-top level?

后端 未结 1 1472
旧巷少年郎
旧巷少年郎 2021-01-21 05:33

This code works as expected:

(define saved #f)
(cons \'wo (call/cc (lambda (k) (set! saved k) \'())))
(saved \'ca!)

output (Racket console):

相关标签:
1条回答
  • 2021-01-21 06:30

    A continuation is all that's left to be done in the execution context where it's saved.

    In the first case, the continuation is saved when calling cons, so it's just to cons 'wo to something and return to the REPL.

    In the second case, you call procedure test, so the continuation is both

    1. cons 'wo to something
    2. call the procedure bound to saved (i.e. the continuation) with 'ca!

    so the continuation calls itself, hence the loop.

    0 讨论(0)
提交回复
热议问题