3.8. kink/EVALUATOR

Provides interface to the evaluator.

3.8.1. EVALUATOR.run($body $on_returned $on_raised)

`run` invokes $body in a new evaluator.

Preconditions:

• $body must be a thunk fun

• $on_returned must be a fun which takes as the result of the invocation of $body as the only argument

• $on_raised must be a fun which takes an exceprtion as the single argument.

If the evaluator terminates without raising an exception, EVALUATOR.run tail-calls $on_returned with the result of the execution stack.

If the evaluator terminates raising an exception, EVALUATOR.run tail-calls $on_raised with the exception.

Example:

:EVALUATOR.require_from('kink/')
:TRACE.require_from('kink/')

:divide_10_in_new_stack <- {(:Divisor)
  EVALUATOR.run(
    { 10 // Divisor }
    {(:Result)
        stdout.print_line('result: {}'.format(Result))
    }
    {(:Exc)
      Exc.desc_iter.each{(:Line)
        stdout.print_line(Line)
      }
    }
  )
}

divide_10_in_new_stack(2)
# Output:
#   result: 5

divide_10_in_new_stack(0)
# Output:
#   EXCEPTION
#   {(stdin) L6 C10 op_intdiv} { 10 -->// Divisor }
#   Num.op_intdiv: zero division: 10 is divided by 0