4.12. kink/KONT_TAG

Provides shift/reset operations of tagged delimited continuation.

Using reset/shift pair, the continuation can be extracted as a fun. Example:

:KONT_TAG.require_from('kink/')

:Tag <- KONT_TAG.new
:paren <- Tag.reset{
  '(' + Tag.shift{(:k) $k } + ')'
}

stdout.print_line(paren('foo')) # => (foo)
stdout.print_line(paren('bar')) # => (bar)

If `shift` is not called, `reset` returns the result of $thunk.

:KONT_TAG.require_from('kink/')
:Tag <- KONT_TAG.new
:R <- Tag.reset{ 42 }
stdout.print_line(R.repr) # => 42

Essential parts of kont_tag methods are described as sequences of abstract instructions. See Language specification → Evaluation section for abstract instructions and the abstract stack machine.

4.12.1. type kont_tag

kont_tag is a continuation tag, which identifies delimitor frames on the execution stack.

4.12.1.1. Kont_tag.reset($thunk)

`reset` delimits the continuation with `Kont_tag`.

At the tail of `reset`, the following sequence of abstract instructions is evaluated:

(val $thunk)
(nada)
(emptyvec)
(call call)
(val Kont_tag)
(delimit)

4.12.1.2. Kont_tag.shift($abort)

`shift` makes a continuation fun delimited by `Kont_tag`, moves to `Kont_tag`, and calls $abort with the continuation fun.

At the tail of `shift`, the following sequence of abstract instructions is evaluated:

(val $abort)
(val Kont_tag)
(kont)
(val Kont_tag)
(abort)

4.12.1.3. Kont_tag.can_shift?

`can_shift?` returns whether `shift` can be invoked for `Kont_tag`.

At the tail of `can_shift?`, the following sequence of abstract instructions is evaluated:

(val Kont_tag)
(canshift)

4.12.2. KONT_TAG.new

`new` makes a kont_tag.

4.12.3. KONT_TAG.is?(Val)

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

4.12.4. KONT_TAG.escape_tag

`escape_tag` returns the escape tag, which is a kont_tag used by exceptions and CONTROL.with_break.