6.13. kink/KONT_TAG¶
Provides shift/reset operations of tagged delimited continuation.
Using reset/shift pair, the continuation can be extracted as a function. 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
The methods of `kont_tag` are described with sequences of abstract instructions. See Language specification → Evaluation section for abstract instructions and the abstract stack machine.
6.13.1. type kont_tag¶
`kont_tag` is a delimiter of a delimited continuation.
6.13.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)
Precondition
$thunk must be a thunk.
6.13.1.2. Kont_tag.shift($abort)¶
`shift` makes a continuation function delimited by `Kont_tag`, moves to `Kont_tag`, and calls $abort with the continuation function.
At the tail of `shift`, the following sequence of abstract instructions is evaluated:
(val $abort)
(val Kont_tag)
(kont)
(val Kont_tag)
(abort)
Preconditions
Kont_tag.can_shift? == true
$abort must be a function which takes a continuation function.
6.13.1.3. Kont_tag.can_shift?¶
`can_shift?` returns whether `shift` can be invoked for `Kont_tag` at the current stack.
At the tail of `can_shift?`, the following sequence of abstract instructions is evaluated:
(val Kont_tag)
(canshift)
6.13.2. KONT_TAG.new¶
`new` returns a new `kont_tag`.
6.13.3. KONT_TAG.is?(Val)¶
`is?` returns whether `Val` is a `kont_tag`.