【问题标题】:Is call/cc a copy of a stack frame or an actual jump in execution?call/cc 是堆栈帧的副本还是执行中的实际跳转?
【发布时间】: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


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 2011-08-01
    • 2013-10-31
    • 2010-12-30
    • 2012-09-12
    • 2016-02-26
    • 1970-01-01
    • 2019-07-06
    • 2017-01-31
    • 2016-08-13
    相关资源
    最近更新 更多