PtcRunner.Lisp.Eval.Context (PtcRunner v0.4.1)

View Source

Evaluation context for the Lisp interpreter.

Bundles the parameters that flow through recursive evaluation:

  • ctx: External data (read-only)
  • user_ns: User namespace (mutable bindings from def)
  • env: Lexical environment (variable bindings)
  • tool_exec: Tool executor function
  • turn_history: Previous turn results for multi-turn loops

Summary

Functions

Appends a print message to the context.

Increments the iteration count and checks against the limit.

Merges new bindings into the environment.

Creates a new evaluation context.

Sets a new loop limit, respecting the hard maximum.

Updates the user namespace in the context.

Types

t()

@type t() :: %PtcRunner.Lisp.Eval.Context{
  ctx: map(),
  env: map(),
  iteration_count: integer(),
  loop_limit: integer(),
  prints: [String.t()],
  tool_exec: (String.t(), map() -> term()),
  turn_history: list(),
  user_ns: map()
}

Functions

append_print(context, message)

@spec append_print(t(), String.t()) :: t()

Appends a print message to the context.

increment_iteration(context)

@spec increment_iteration(t()) :: {:ok, t()} | {:error, :loop_limit_exceeded}

Increments the iteration count and checks against the limit.

merge_env(context, bindings)

@spec merge_env(t(), map()) :: t()

Merges new bindings into the environment.

new(ctx, user_ns, env, tool_exec, turn_history)

@spec new(map(), map(), map(), (String.t(), map() -> term()), list()) :: t()

Creates a new evaluation context.

Examples

iex> ctx = PtcRunner.Lisp.Eval.Context.new(%{}, %{}, %{}, fn _, _ -> nil end, [])
iex> ctx.user_ns
%{}

set_loop_limit(context, new_limit)

@spec set_loop_limit(t(), integer()) :: t()

Sets a new loop limit, respecting the hard maximum.

update_user_ns(context, new_user_ns)

@spec update_user_ns(t(), map()) :: t()

Updates the user namespace in the context.