如何分析call/cc中的等效接收器?

how to analyze the equivalent receiver in call/cc?

我正在阅读 Scheme and the Art of Programming 一书,但想不出以下问题的答案:

如果 r

(escaper (lambda (continuation) (continuation body))

(... (call/cc r) ...)中,什么时候可以把r改写成

(lambda (continuation) body)

答案是:总是

escaper 不是方案的一部分。它由那本书 Scheme and the Art of Programming 定义,因此:

" escaper turns its argument procedure into similarly defined 'escape' procedure (a.k.a. 'continuation'), which, when invoked, its result becomes the result of the entire computation. Anything awaiting the result [of that escape procedure's invocation] is ignored." (slightly copy-edited)

(continuation body)在“escaper-ed”版本(lambda (c..n) (c..n body))[=66=中的结果] 直接return编辑到顶层,除了continuation不会return。它它的目标上下文(1),即that等待(call/cc r) 调用,因为 this continuation 是由对 call/cc:

的调用设置的
           ;; (0)   -- top level
             (... 
                  ;; (1)  <-----------------------------------\
                    (call/cc r)  ;; r = (escaper (lambda (continuation)
                                 ;;                 (continuation body)))
                         ...)
===
           ;; (0)   -- top level
             (... 
                  ;; (1)  
                    (continuation--0                       ;; set up by `escaper`
                      ((lambda (continuation)
                            (continuation body))
                        continuation--1))                   ;; set up by call/cc
                         ...)
===
           ;; (0)   -- top level
             (... 
                  ;; (1)  
                    (continuation--0
                       (let ((continuation continuation--1))   ;; by application of `lambda`
                         (continuation body)))
                         ...)

所以如果bodyreturns,那个结果被continuation--1传递给(1);如果 body 使用一个值调用 continuation,则该值由 continuation--1 传递到 (1)。没有任何内容被 return 编辑到 continuation--0,所以它的跳跃永远不会被触发。

并且在

           ;; (0)
             (... 
                  ;; (1)
                    (call/cc (lambda (continuation) body))
                         ...)
===
           ;; (0)
             (... 
                  ;; (1)
                    (let ((continuation continuation--1)) 
                       body)
                         ...)

发生完全相同的事情:如果 body returns,结果只是 returned 到 (1) ;如果 body 使用一个值调用 continuation,则该值由 continuation--1.

传递到 (1)