`

Continuation

阅读更多

Continuation

From Wikipedia, the free encyclopedia

Jump to: navigation , search

 

In computing and programming , a continuation is an abstract representation of the control state , or the "rest of computation" or "rest of code to be executed". This is closely linked with what part of the program you are in: which function and which line is being executed. The "current continuation " or "continuation of the computation step" are the instructions that will be executed after the current line of code is executed.


The term continuations can also be used to refer to first-class continuations , which are constructs that give a programming language the ability to save the execution state at any point and return to that point at a later point in the program.


Programs must allocate space in memory for the variables its functions use. Most programming languages use a call stack for storing the variables needed because it allows for fast and simple allocating and automatic deallocation of memory. There are also programming languages that use a heap for this, which allows for flexibility but with a higher cost for allocating and deallocating memory. These two different implementations both have benefits and drawbacks in the context of continuations.[ 1]


Almost all languages have a means for manipulating the order of execution steps (i.e. manipulating the continuation of a computation step). The goto is the most basic form of this. Control structures like if statements , loops , return statements , break statements , and exit are more structured (and limited) ways to manipulate the order of executing instructions and are essentially limited goto statements.


More complex constructs exist as well. For example in C , setjmp can be used to jump from the middle of one function to another function, provided the second function is lower on the stack (if it is waiting for the first function to return, possibly among others). Other more complex examples include coroutines in Simula 67 , tasklets in Stackless Python , generators Icon and Python , continuations in Scala (starting in 2.8), fibers in Ruby (starting in 1.9.1), the backtracking mechanism in Prolog , and threads .  

 

Read More...

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics