On this page:
Continuation
Continuation.prompt
Continuation.capture
Continuation.escape
Continuation.Prompt  Tag
Continuation.Prompt  Tag.make
Continuation.Prompt  Tag.default
Continuation.Marks
Continuation.Marks.current
Continuation.with_  mark
Continuation.call_  with_  immediate_  mark
Continuation.call_  in
8.12

6.19 Continuations🔗ℹ

annotation

Continuation

Recognizes continuations as captured by Continuation.capture.

expression

Continuation.prompt maybe_tag_expr:

  body

  ...

  maybe_catch

 

maybe_tag_expr

 = 

tag_expr

 | 

ϵ

 

maybe_catch

 = 

~catch arg_bindings: body; ...

 | 

~catch

| arg_bindings: body; ...

| ...

 | 

~catch: entry_point

 | 

ϵ

 

arg_bindings

 = 

bind

 | 

(bind, ...)

Returns the value of the body sequence, but also establishes a delimiting continuation prompt around the sequence. If tag_expr is present, is determines the tag used for the prompt, otherwise Continuation.PromptTag.default is used.

The ~catch clauses is superficially similar to ~catch in try, but ~catch in Continuation.prompt does not cath exceptions. Instead, it determines a handler that is used to receive any values delivered to the prompt via Continuation.escape. The handler is call with the continuation of the Continuation.prompt form. Since mutiple values can be delivered by an escape, the ~catch construction can accept mutiple values or dispatch on the number of values received. The default prompt handler expects a single thunk, and calls the thunk under a prompt with the same tag as the handler’s prompt.

Captures the continuation of the Continuation.capture expression, binds it to id, and then evaluates the body sequence in tail position. The continuation is represented as a function that accepts values to deliver to the continuation.

The captured continuation is delimited by a prompt with the tag specified by tag_expr, where Continuation.PromptTag.default is used if tag_expr is not present. A prompt with the designated tag must be present in the current continuation at the time of capture.

The captured continuation is composable, which means that the capture continuation extends the current one when it is called, and no prompt is required in the continuation of the call to the capture continuation.

function

fun Continuation.escape(

  ~tag: tag :: Continuation.PromptTag:

          Continuation.PromptTag.default,

  val :: Any, ...

) :: None

Escapes to the nearest prompt in the current continuation that has the prompt tag tag, delivering the vals to the prompt’s handler.

Recognizes prompt tags as produced by Continuation.PromptTag.make.

Creates a fresh prompt tag or accesses a default prompt tag.

If name is provided to Continuation.PromptTag.make, it is used only for printing and other debugging purposes.

Recognizes continuation marks as returned by Continuation.Marks.current.

Returns the marks of the current continuation.

Sets the current frame’s continuation mark for the result of key_expr to the result of val_expr and evaluates the body sequence in tail postion.

function

fun Continuation.call_with_immediate_mark(

  key :: Any,

  ~default: default :: Any = #false,

  fn :: Function.of_arity(1)

)

Calls fn in tail position, providing as its argument the current frame’s mark value for key, or default if the current frame has no mark for key.

function

fun Continuation.call_in(cont :: Continuation,

                         fn :: Function.of_arity(0))

  :: None

Calls fn with the current continuation extended with cont. This means the extension happens before the call, not after.