Computes the anti-unification (most specific generalization) of two ASTs.
Given two AST fragments, anti-unification finds the largest common structure and replaces every position where the trees diverge with a hole — a generated variable. The result is the pattern that, when the holes are filled with the right values, reconstructs either original.
This directly produces the shape of a function that could replace both fragments: the common structure becomes the body, and the holes become parameters.
Example
iex> a = quote do: Enum.map(list, fn x -> x * 2 end)
iex> b = quote do: Enum.map(items, fn y -> y * 3 end)
iex> {pattern, holes} = ExDNA.AST.AntiUnifier.anti_unify(a, b)
iex> length(holes)
3Each hole is %{var: atom, values: [left_ast, right_ast]}.
Summary
Functions
Compute the anti-unification of two AST fragments.