3.8. kink/EVALUATOR

Provides interface to the evaluator.

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

EVALUATOR.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 (Msg, Traces) as the arguments, where Msg is an exception message str, and Traces is a vec of exception traces

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 message str and a vec of the traces.

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))
    }
    {(:Msg :Traces)
      TRACE.format_traces(Msg Traces).each{(:Line)
        stdout.print_line(Line)
      }
    }
  )
}

divide_10_in_new_stack(2)
# Output:
#   result: 5

divide_10_in_new_stack(0)
# Output:
#   exception traces: from oldest to newest
#   [(stdin) L6 C10 op_intdiv] { 10 -->// Divisor }
#   exception message: Num.op_intdiv: zero division: 10 is divided by 0