PtcRunner.Lisp.Eval (PtcRunner v0.4.1)

View Source

Evaluates CoreAST into values.

The eval layer recursively interprets CoreAST nodes, resolving variables from lexical environments, applying builtins and user functions, and handling control flow.

Module Structure

This module delegates to specialized submodules:

  • Eval.Context - Evaluation context struct
  • Eval.Patterns - Pattern matching for let bindings
  • Eval.Where - Where predicates and comparisons
  • Eval.Apply - Function application dispatch
  • Eval.Helpers - Type errors and utilities

Summary

Types

env()

@type env() :: %{required(atom()) => term()}

runtime_error()

@type runtime_error() ::
  {:unbound_var, atom()}
  | {:not_callable, term()}
  | {:arity_mismatch, expected :: integer(), got :: integer()}
  | {:type_error, expected :: String.t(), got :: term()}
  | {:tool_error, tool_name :: String.t(), reason :: term()}
  | {:invalid_keyword_call, atom(), [term()]}
  | {:arity_error, String.t()}
  | {:destructure_error, String.t()}
  | {:cannot_shadow_builtin, atom()}

tool_executor()

@type tool_executor() :: (String.t(), map() -> term())

value()

@type value() ::
  nil
  | boolean()
  | number()
  | String.t()
  | atom()
  | list()
  | map()
  | MapSet.t()
  | function()
  | {:closure, [PtcRunner.Lisp.CoreAST.pattern()], PtcRunner.Lisp.CoreAST.t(),
     env(), list()}

Functions

eval(ast, ctx, memory, env, tool_executor, turn_history \\ [])

@spec eval(PtcRunner.Lisp.CoreAST.t(), map(), map(), env(), tool_executor(), list()) ::
  {:ok, value(), map()} | {:error, runtime_error()}

eval_with_context(ast, ctx, memory, env, tool_executor, turn_history \\ [])

@spec eval_with_context(
  PtcRunner.Lisp.CoreAST.t(),
  map(),
  map(),
  env(),
  tool_executor(),
  list()
) ::
  {:ok, value(), PtcRunner.Lisp.Eval.Context.t()} | {:error, runtime_error()}