PtcRunner.Lisp.Eval.Helpers (PtcRunner v0.15.0)

Copy Markdown View Source

Shared helper functions for Lisp evaluation.

Provides type error formatting and type description utilities.

Summary

Functions

Returns the definition-only-form hint for the first matching name, or nil.

Describes the type of a value for error messages.

Formats closure errors with helpful messages.

Generates a type error tuple for FunctionClauseError in builtins.

Returns the trailing hint for one or more unresolved names, or "".

Functions

definition_only_hint(names)

@spec definition_only_hint(term()) :: String.t() | nil

Returns the definition-only-form hint for the first matching name, or nil.

Accepts one name or a list of them, and answers nil for anything else so callers projecting untrusted diagnostic detail need no shape check first.

describe_type(callable)

@spec describe_type(term()) :: String.t()

Describes the type of a value for error messages.

format_closure_error(reason)

@spec format_closure_error(term()) :: String.t()

Formats closure errors with helpful messages.

type_error_for_args(fun, args)

@spec type_error_for_args(function(), [term()]) :: {:type_error, String.t(), term()}

Generates a type error tuple for FunctionClauseError in builtins.

unresolved_name_suffix(names)

@spec unresolved_name_suffix(term()) :: String.t()

Returns the trailing hint for one or more unresolved names, or "".

A failed lookup takes the highest rung it can reach: name one alternative that was resolved first, list the bounded set the name must have come from, or point at search. The rungs are not interchangeable — the first two cost the model no turns and the third costs one — and none of them may print a name that was not looked up, because a plausible name that does not exist costs the same turn twice.

A form that is absent by category — an import, a macro, constructed-source evaluation, file I/O — is told so. Pointing those at search spends a turn on a query that cannot succeed.

Several unresolved names share one message, and neither a suggestion nor a search term for one of them applies to the rest, so only the category rungs run for a list.