Pattern matching for let bindings in Lisp evaluation.
Handles destructuring patterns including variables, map destructuring, sequence destructuring, and :as patterns.
Summary
Functions
Coerces a value to match the expected shape of a pattern.
Matches a pattern against a value, returning variable bindings on success.
Types
Functions
Coerces a value to match the expected shape of a pattern.
Used for rest-arg keyword arguments: when a variadic rest pattern expects map destructuring, converts a flat key-value list to a map. Returns an error tuple for odd-length lists. Returns the value unchanged for non-map patterns.
Examples
iex> pattern = {:destructure, {:keys, [:a], []}}
iex> PtcRunner.Lisp.Eval.Patterns.coerce_for_pattern(pattern, [:a, 1])
%{a: 1}
iex> PtcRunner.Lisp.Eval.Patterns.coerce_for_pattern({:var, :xs}, [1, 2])
[1, 2]
@spec match_pattern(pattern(), term()) :: match_result()
Matches a pattern against a value, returning variable bindings on success.