- Documentation
- Reference manual
- Built-in Predicates
- Notation of Predicate Descriptions
- Character representation
- Loading Prolog source files
- Editor Interface
- List the program, predicates or clauses
- Verify Type of a Term
- Comparison and Unification of Terms
- Control Predicates
- Meta-Call Predicates
- Delimited continuations
- Exception handling
- Handling signals
- DCG Grammar rules
- Database
- Declaring predicate properties
- Examining the program
- Input and output
- Status of streams
- Primitive character I/O
- Term reading and writing
- Analysing and Constructing Terms
- Analysing and Constructing Atoms
- Localization (locale) support
- Character properties
- Operators
- Character Conversion
- Arithmetic
- Misc arithmetic support predicates
- Built-in list operations
- Finding all Solutions to a Goal
- Forall
- Formatted Write
- Global variables
- Terminal Control
- Operating System Interaction
- File System Interaction
- User Top-level Manipulation
- Creating a Protocol of the User Interaction
- Debugging and Tracing Programs
- Obtaining Runtime Statistics
- Execution profiling
- Memory Management
- Windows DDE interface
- Miscellaneous
- Built-in Predicates
- Packages
- Reference manual
4.10 Delimited continuations
The predicates reset/3 and shift/1 implement delimited continuations for Prolog. Delimited continuation for Prolog is described in Schrijvers et al., 2013. The mechanism allows for proper coroutines, two or more routines whose execution is interleaved, while they exchange data. Note that coroutines in this sense differ from coroutines realised using attributed variables as described inĀ chapter 7.
The suspension mechanism provided by delimited continuations is
suitable for the implementation of tabling
Desouter et
al., 2015, see library library(tabling)
.
- reset(:Goal, ?Ball, -Continuation)
- Call Goal. If Goal calls shift/1
and the argument of shift/1
can be unified with Ball,66The
argument order described in Schrijvers et
al., 2013 is
reset(Goal,Continuation,Ball)
. We swapped the argument order for compatibility with catch/3 shift/1 causes reset/3 to return, unifying Continuation with a goal that represents the continuation after shift/1. In other words, meta-calling Continuation completes the execution where shift left it. If Goal does not call shift/1, Continuation are unified with the integer0
(zero).67Note that older versions also unify Ball with0
. Testing whether or not shift happened on Ball however is always ambiguous. - shift(+Ball)
- Abandon the execution of the current goal, returning control to just after the matching reset/3 call. This is similar to throw/1 except that (1) nothing is `undone' and (2) the 3th argument of reset/3 is unified with the continuation, which allows the code calling reset/3 to resume the current goal.