6.9. kink/DYN

6.9.1. type dyn

A `dyn` is a tag of values which are pushed and popped on the call stack.

The name `dyn` comes from “dynamic scope”, as it acts like dynamically scoped variables of some dialects of Lisp.

A `dyn` can be used to carry runtime context, such as transactions. See the following example:

6.9.1.1. Dyn.with(Val $thunk)

`with` pushes `Val`, associating it with `Dyn`, on the call stack, and calls $thunk with no arg. When the invocation of $thunk exits, `Val` is popped from the call stack.

Precondition

$thunk must be a thunk.

6.9.1.2. Dyn.all

`all` returns a vec of values associated with `Dyn`, in the order from the bottom of the call stack to the top of the call stack.

Example

6.9.1.3. Dyn.top

`top` returns the value associated with `Dyn` which is closest to the top of the call stack.

Precondition

At least one value must be associated with `Dyn` in the call stack.

Example

6.9.1.4. Dyn.any?

`any?` returns whether any value is associated with `Dyn` in the call stack.

Example

6.9.2. DYN.new

`new` makes a new `dyn`.

6.9.3. DYN.is?(Val)

`is?` returns whether `Val` is a `dyn`.