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

10.3 Continuations🔗ℹ

A continuation represents a captured evaluation context. Control can “jump” into a continuation by delivering values to it, or by using it with Continuation.in.

annotation

Continuation

Recognizes continuations as captured by Continuation.capture. Continuations are callable as functions and satisfy Function.

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(s) of the body sequence, but also establishes a delimiting continuation prompt around the sequence. If tag_expr is present, it 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 catch 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 multiple values can be delivered by an escape, the ~catch construction can accept multiple 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 callable as a function that accepts values to deliver to the continuation, but it can also be used with Continuation.in.

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.

expression

Continuation.in cont_expr:

  body

  ...

Evaluates the body sequence “in” the captured continuation produced by cont_expr, as opposed to delivering values to it. More precisely, the current continuation is extended with the captured continuation, and the body sequence is evaluated with that as the 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.

expression

Continuation.barrier:

  body

  ...

Like block, but disallowing a continuation capture during the body that extends to the context of the Continuation.barrier form.

> Continuation.barrier:

    Continuation.capture k:

      k

Continuation.capture: cannot capture past continuation barrier

> Continuation.barrier:

    Continuation.prompt:

      Continuation.capture k:

        k

#<function>

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 position.

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.