Prompts¶
The prompts library (import (prompts)) provides dynamic delimited
continuations.
Delimited continuations in Scheme are created by enclosing some procedure in
what is called a prompt, so-called because it resembles the REPL prompt. Code
running in a prompt has the ability to abort to a prompt handler, passing along
its current continuation at the time. Unlike the continuation obtained from
call/cc, the continuation of a prompt does not extent beyond the prompt
handler.
Dynamic delimited continuations further extend this by allowing prompts to be
attached with a prompt tag. The prompt tag allows for code to decide at
runtime which prompt they should extend to by invoking abort-to-prompt with
the desired prompt tag.
Continuations can be quite mind-bending by themselves, but dynamic delimited continuations take them to a whole new level. Experiment with them and most importantly have fun!
Warning
Delimited continuations in scheme-rs are not fully fleshed out and are expected to change in the future at least to some degree.
🐉 Hic sunt dracones! 🐉
call-with-prompt procedure¶
Installs a prompt with the given tag and handler and invokes thunk.
tag must be a Symbol.
abort-to-prompt procedure¶
Calls the handler of the prompt installed with tag with the current
continuation such that the current continuation does not extend past the prompt.
Examples¶
| Example: installing a prompt | |
|---|---|
This code will print "hello", and every subsequent call to print-goodbye will
print "goodbye". This code can be thought of as functionally equivalent to the
following: