March 21th Wednesday (三月 二十一日 水曜日)

来源:互联网 发布:网络交换器什么牌子好 编辑:程序博客网 时间:2024/05/05 13:32

(call-with-current-continuation proc)

  Proc must be a procedure of one argument. The procedure call-with-current-continuation (which is the
same as the procedure call/cc) packages the current continuation as an “escape procedure” and passes
it as an argument to proc.  The escape procedure is a Scheme procedure that, if it is later called,
will abandon whatever continuation is in effect at that later time and will instead use the continuation that was in effect when the escape procedure was created. Calling the escape procedure
 may cause the invocation of before and after thunks installed using dynamic-wind.
  The escape procedure accepts the same number of arguments as the continuation of the original call to call-with-current-continuation.  The escape procedure that is passed to proc has unlimited extent
 just like any other procedure in Scheme.  It may be stored in variables or data structures and may be called as many times as desired.

  A common use of call-with-current-continuation is for structured, non-local exits from loops or
 procedure bodies, but in fact call-with-current-continuation is useful for implementing a wide
 variety of advanced control structures.

 Whenever a Scheme expression is evaluated there is a continuation wanting the result of the
expression.  The continuation represents an entire (default) future for the computation.  Most
of the time the continuation includes actions specified by user code, as in a continuation that will
 take the result, multiply it by the value stored in a local variable, add seven, and store the
result in some other variable. Normally these ubiquitous continuations are hidden behind the scenes
and programmers do not think much about them. On rare occasions, however, a programmer may need to deal with continuations explicitly.  The call-with-current-continuation procedure allows Scheme
programmers to do that by creating a procedure that acts just like the current continuation.

  Most programming languages incorporate one or more specialpurpose escape constructs with names like exit, return, or even goto.  In 1965, however, Peter Landin [29] invented a general purpose escape
 operator called the J-operator.  John Reynolds [38] described a simpler but equally powerful
construct in 1972.  The catch special form described by Sussman and Steele in the 1975 report on Scheme is exactly the same as Reynolds’s construct, though its name came from a less general construct in MacLisp.  Several Scheme implementors noticed that the full power of the catch construct
could be provided by a procedure instead of by a special syntactic construct, and the name call-with-current-continuation was coined in 1982.  This name is descriptive, but opinions differ on the merits
of such a long name, and some people use the name call/cc instead.

(values obj . . .)

  Delivers all of its arguments to its continuation.  The values procedure might be defined as
follows:

(define (values . things)
  (call-with-current-continuation
    (lambda (cont) (apply cont things))))
 

原创粉丝点击