Raxol.REPL.Evaluator (Raxol v2.3.0)

View Source

Elixir code evaluator with timeout protection, IO capture, and persistent bindings.

Each evaluator maintains its own binding context across evaluations, so variables defined in one eval call are available in the next.

evaluator = Evaluator.new()
{:ok, result, evaluator} = Evaluator.eval(evaluator, "x = 1 + 2")
{:ok, result, evaluator} = Evaluator.eval(evaluator, "x * 10")
result.value  #=> 30

Summary

Functions

Returns the list of current variable bindings as [{name, value}].

Clears evaluation history, keeping bindings.

Evaluates code in the evaluator's binding context.

Returns evaluation history as [{code, result}], newest first.

Creates a new evaluator with an empty binding context.

Resets all bindings, keeping history.

Types

result()

@type result() :: %{value: term(), output: String.t(), formatted: String.t()}

t()

@type t() :: %Raxol.REPL.Evaluator{
  bindings: keyword(),
  env: Macro.Env.t(),
  history: [{String.t(), result()}]
}

Functions

bindings(evaluator)

@spec bindings(t()) :: keyword()

Returns the list of current variable bindings as [{name, value}].

clear_history(evaluator)

@spec clear_history(t()) :: t()

Clears evaluation history, keeping bindings.

eval(evaluator, code, opts \\ [])

@spec eval(t(), String.t(), keyword()) ::
  {:ok, result(), t()} | {:error, String.t(), t()}

Evaluates code in the evaluator's binding context.

Returns {:ok, result, new_evaluator} on success or {:error, reason, evaluator} on failure. Bindings persist across calls. IO output is captured separately from the return value.

history(evaluator)

@spec history(t()) :: [{String.t(), result()}]

Returns evaluation history as [{code, result}], newest first.

new(opts \\ [])

@spec new(keyword()) :: t()

Creates a new evaluator with an empty binding context.

reset_bindings(evaluator)

@spec reset_bindings(t()) :: t()

Resets all bindings, keeping history.