【发布时间】:2015-02-09 05:29:28
【问题描述】:
我不明白以下如何不设置无限循环:
(define call/cc call-with-current-continuation) ; ccc alias
(define return #f) ; declare a global variable 'return'
(+ 1 (call/cc (lambda (cont) ; setup continuation with 'cont' as the exit procedure
(set! return cont) ; set global var 'return' to the exit procedure
1)))
(return 22) ; 23
当我调用(return 22) 时,我跳回到延续,但传递的值22 作为call/cc 表单的新评估结果。这不会导致(return 22) 被评估为下一条语句,从而设置一个无限循环吗?
我知道这不是无限循环,但我不明白为什么不是。
【问题讨论】:
-
看看this是否有帮助。
标签: scheme infinite-loop continuations continuation-passing callcc