The difference between delimited and undivided continuations

I think the difference between delimited and undelimited is similar to the difference between call and jump .

If we run the delimited continuation, it will return to the caller after it finishes. If we call the undelimited continuation, it works like goto and never returns to the caller.

Does it make sense? Am I missing something?

+6
source share
2 answers

You are a little behind. The sequels, of any taste, have nothing to do with goto (jumping). However, they have everything related to the stack.


Classical sequels

Remember that regular continuations capture the concept of a management stack as first-class values. Stacks can be named, passed as arguments, and values ​​can be applied to them, leading to a change in the control flow, with a simple API based on a function application via callCC .

Limited Account Assignments

What adds separation extensions to the mix?

Recall that regular continuations capture the entire call stack to a certain point. What if we could put markers in this to say exactly what part of the control stack we need to keep in continuation? This is a kind of "demarcation" of the management stack.

This is an idea, and now you have super-cool delimited sequels: delimit, capture and manipulate arbitrary parts of the program as a value. Ideal for renewal and incremental processing, as well as for other complex flow control methods.

References

Notes

Some corrections from Oleg Kiselev , got off-list:

  • Continuations and jumps are deeply connected, the first discoveries of continuations were in the context of an attempt to understand the semantics of jumps or move on. For this purpose, the operator Landin J was introduced; J is the precursor to the / cc call. See Landins Introduction to Jumps and Shortcuts Summary
  • Further reading of unsupported, “regular” continuations in “Undelimited continuations are co-values, not functions,” and their basics.
+7
source

A continuation as a language function (as opposed to a continuation as a programming template) is the redefinition of (parts of) the control context ("stack"). As Don said, undivided continuations represent the whole context, while delimited continuations represent only part of it.

As a rule, capturing an unlimited continuation (for example, with call/cc ) does not change the control context; the control context changes only when the continuation is called (i.e., it is reflected on the stack).

Typically, capturing a delimited continuation (e.g. using shift ) immediately breaks the control context segment to the nearest delimiter (e.g. reset ) and confirms this as what seems like a plain old function (although this could be implemented as a stack trick rather than implemented ordinary functions).

By the way, continuations are sometimes called "first-class jumps," but this does not mean that they are more associated with the jmp instruction than a regular function call.

+2
source

Source: https://habr.com/ru/post/888539/


All Articles