4

我不明白以下内容如何不设置无限循环:

(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)被评估为下一条语句,从而设置一个无限循环吗?

我知道这不是无限循环,但我不明白为什么不是。

4

1 回答 1

4

一个无限循环。但是,在大多数 Scheme 实现中,顶级表单是在prompts中评估的。

如果你把你的表达式放在 a(let () ...)中,比如说,你肯定会看到无限循环在起作用。

于 2014-12-10T22:17:38.210 回答